Home > front end >  Where should I put React component's assets?
Where should I put React component's assets?

Time:01-13

I'm working on a structure for a React application. We have ./src/Assets/Images folder, but should I put all component assets there? or I should put each component's assets to it's folder?

I mean: ./src/Components/Loading/animation.gif

or: ./src/Assets/Images/animation.gif

I'm actually interested to design a maintainable and clear structure for this app.

What do you think? which pattern is better for development and the feature...

You know, I've separated Styles but have doubt on Images??

CodePudding user response:

This must be an opinion based question and it isn't something you should care that much about to be honest. It's personal preference but if you ask me, it's better to keep you assets in a same folder so your components' structure won't get messy.

CodePudding user response:

I would like to say "all in one place" is good. Assets that are required to be loaded, for example images for navigation should be placed in public folder as it is much more comfortable to use. You just need to set url to point it.

For other cases, I think it is better to place it in component's folder. I think tree structure is easy to maintain and scalable. Let's imagine that you need to update a component. In that case, you just need to update files in the same folder. If it is located somewhere else, this can lead to potential problems: for example, you need to make sure that it is not used by other files.

To sum up, I think it is good to place assets in the component's folder.

  •  Tags:  
  • Related