Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  50] [ 3]  / answers: 1 / hits: 23484  / 9 Years ago, thu, september 17, 2015, 12:00:00

I’m using redux and I’m not sure about how to organize my components, I think the best is to keep them in folders with the name of the main component as the name of the folder and all inner components inside:




components
Common/ things like links, header titles, etc
Form/ buttons, inputs, etc
Player/ all small components forming the player
index.js this one is the top layout component
playBtn.js
artistName.js
songName.js
Episode/ another component


Then, in the containers folder, I’ve one container per page, that are the only ones I'm actually connecting to Redux:




containers/
HomePageApp.js
EpisodePageApp.js
...


and then the actions are one per each top component, instead of one per page, so in the page container that I connect to Redux I pass all the actions of the components used in that page. For example:




actions/
Player.js
Episode.js
...


Am I doing this right? I haven't found much information about it googling, and the ones I've found I think they are limited to small projects.



Thanks!


More From » reactjs

 Answers
12

In the official examples we have several top-level directories:




  • components for “dumb” React components unaware of Redux;

  • containers for “smart” React components connected to Redux;

  • actions for all action creators, where file name corresponds to part of the app;

  • reducers for all reducers, where file name corresponds to state key;

  • store for store initialization.



This works well for small and mid-level size apps.



When you want to go more modular and group related functionality together, Ducks or other ways of grouping functionality by domain is a nice alternative way of structuring your Redux modules.



Ultimately choose whatever structure works best for you. There is no way Redux authors can know what’s convenient for you better than you do.


[#65027] Wednesday, September 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uriahw

Total Points: 372
Total Questions: 93
Total Answers: 115

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
;