What is your preferred way of structuring files and folders in react ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is your preferred way of structuring files and folders in react ?

9th Aug 2020, 7:26 AM
Logomonic Learning
Logomonic Learning - avatar
5 Answers
+ 5
You structure it however you structure it. Everyone has different views on writing code, which is fine! If you’re asking the community how everyone does it, then your feed would be a better place for this question.
9th Aug 2020, 8:06 AM
Rowsej
Rowsej - avatar
+ 5
I don't have so much experience that I have a preferred folder structure yet but at work we have seperate folders for styles, redux-actions, redux-models, redux-reducers, type definitions, shared components, and views (the main sites in your app). It works reasonably ok. A single component folder which contains all components will only get you so far and it gets messy quickly, so if I had the liberty to re-do all the existing projects I would be more liberal with subfolders. And I would just let my programmer senses guide me, just like we break code into smaller functions we can break large folders into subfolders, on a case-by-case basis.
9th Aug 2020, 10:01 AM
Schindlabua
Schindlabua - avatar
+ 2
Logomonic Learning There are a few common approaches popular in the ecosystem you may want to consider. • Grouping by features or routes • Grouping by file type More information, https://reactjs.org/docs/faq-structure.html The last advice from Reactjs article is the most important: Don’t overthink it If you’re just starting a project, don’t spend more than five minutes on choosing a file structure. Pick any of the above approaches (or come up with your own) and start writing code!
10th Aug 2020, 6:43 AM
Calviղ
Calviղ - avatar
+ 2
Logomonic Learning I just put them two folders - public and src. However, in the src folder, I would group them by type - scripts, images, sounds, etc.
10th Aug 2020, 7:02 AM
Rowsej
Rowsej - avatar
+ 1
Rowsej so how do you structure your files? Everyone has their own way of structuring files, but all are not equal. E.g. would you suggest dumping all files into a single folder? your response does not help at all! but is esteemed for some reason!?? Ps. People are still asking"which is the best language to study" so please cut this question some slack.
10th Aug 2020, 6:38 AM
Logomonic Learning
Logomonic Learning - avatar