Eliya Cohen Eliya Cohen - 8 months ago 46
React JSX Question

React Core Layout components architectures

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:

  1. Each component with its own style in the same folder.

    Pros: Sounds more modular.


    • I'll have to make a new directory for each component.

    • To make the
      s clearer (and not like
      import CoreComp from 'CoreComp/CoreComp'
      ), I'll have add for each component
      file which will import the component, and it will make much more sense.

  1. Directory of components and separate directory for styles

    Cons: It sounds less modular than the first suggestion.


    • I don't have to make a folder for each component.

    • I don't need to make a

I'm not looking for a discussion about that, I just need to know if there's a popular convension for that.

Answer Source

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.


  • Easy code navigation
  • Easy debugging
  • Easy understanding of the file structure (Better organized file structure in my opinion)
  • Easy to organize unit test files as well.

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).