Reputation: 11498
I'm using React Redux.
Let's say I have some "Core Components" such as Navbar / Header & Footer.
Each component has its own style (SCSS). So I was thinking about doing the architectures in two ways:
Each component with its own style in the same folder.
Pros: Sounds more modular.
Cons:
import
s clearer (and not like import CoreComp from 'CoreComp/CoreComp'
), I'll have add for each component index.js
file which will import the component, and it will make much more sense.Directory of components and separate directory for styles
Cons: It sounds less modular than the first suggestion.
Pros:
index.js
.I'm not looking for a discussion about that, I just need to know if there's a popular convension for that.
Upvotes: 2
Views: 271
Reputation: 15632
1. First of all, don't worry about creating folders. They don't cost you any bytes.
2. For each component, say we have a folder Component
, write the component's code in Component/index.js
and export default
it.
So that you can import just like import Component from './Component';
3. Component's styles go inside Component/styles.scss
.
4. Create sass mixins / functions / variables for common styles, and put it in common.scss
in a common place. @import
it and use wherever you want.
Advantages:
This is what we usually follow in React.js projects.
(Of course like for anything, there will be some people who dismiss this, but I love it this way).
Upvotes: 4