-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
I'm writing a React Native / React Router / Redux app that has 6 main screens, each of which is its own route and is powered by a connected React component.
This is my file organization structure:
components/
foo/
componentA.js
componentB.js
bar/
componentC.js
componentD.js
sharedComponentA.js
sharedComponentB.js
containers/
fooContainer.js
barContainer.js
My app is small enough that the only components that are connected to the Redux store are those that live in my containers
folder. Those containers pass their props down to their children, which live in the components/
subfolder that matches the name of the container.
If I eventually want to connect a component, ie components/foo/componentA
, my organizational structure's division of component vs container implies that I should move componentA
to the containers/
folder. I don't like that I will have to change all of my file paths in my imports/exports inside this component just because I have connected it to the Redux store.
I've begun to view the components inside my containers/
folder as top level concepts or scenes in the app and accordingly thinking about how to structure my app with that in mind.
Here's one idea I am thinking of:
scenes/
foo/
index.js (container)
componentA.js
componentB.js
bar/
index.js (container)
componentC.js
componentD.js
components/
sharedComponentA.js
sharedComponentB.js
In the above structure, files such as componentA
or componentB
could be components or containers, though index.js
is always clearly the top level container for the given scene.
I know there's no right answer to this question. Interested in hearing anyone's experiences with this problem and how they addressed it. Thanks!