I have some untested ideas, and opinions on this.
First, I actually decided I don’t like the idea of the Meteor 1.3 imports
folder. Just make everything lazy loading, and let the developer decide where to import things. Except perhaps CSS.
React naming components: I used to structure my apps like this:
client
├── components
│ ├── DumbSpinner
│ │ ├── DumbSpinner.jsx
│ │ └── DumbSpinner.scss
│ ├── EditModal
│ │ ├── EditModal.jsx
│ │ └── EditModal.scss
│ ├── Greeter
│ │ └── Greeter.jsx
│ ├── IconButton
│ │ ├── IconButton.jsx
│ │ └── IconButton.scss
│ ├── Modal
│ │ ├── Modal.jsx
│ │ └── Modal.scss
│ ├── NewsPopup
│ │ ├── NewsPopup.jsx
│ │ └── NewsPopup.scss
That way every component is tucked away with its CSS. Though in some cases, it might be a good move to inline your styles. A few of us just had a great discussion about inline styles that you may want to read: Inline styles with React - thoughts?
Now with modules, I’m thinking of maybe changing up my structure a bit, and perhaps going for something like this:
client
└── components
├── blog
│ ├── blog.jsx
│ └── blog.scss
└── user-account
├── user-account.jsx
└── user-account.scss
And each JSX file has several React components that are related inside of it. Then I could do cool things like this, when I want to use these:
import {BlogList, BlogItem} from '../components/blog/blog.jsx';
I feel like with components broken down more into stateless components, you could wind up in file hell where you have a whole bunch of files that just have 8-12 lines of code in it, and I’m not sure if I like that kind of setup. I’m curious what other React users think of this idea.
Side note: I’ve seen some people just make folders for components, and name the code inside index.jsx
. I personally don’t like this, because if I have 6 tabs open, they’re all labeled “index.jsx” and I can’t tell what’s what.