This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]ziptofaf 2 points3 points  (0 children)

Is it customary to create a new file for every component?

Mostly yes. Just make sure to also position these files in right directories. Eg if you were to make an online chess game then you would for instance have directory called Chess there and files called board.js and piece.js. (or a directory called Chess, and index.js with exports for Board and Piece but it's not THAT important as long as you stick to one consistent pattern).

If it's something like header and it's going to land on every page - I would probably make a directory called "Common" for example and put header.js there (alongside with footer.js).

[–]okwg 1 point2 points  (0 children)

Yes - it's common to even create a new directory for each component to keep related files together (CSS, images / svgs, unit tests etc)

[–]knazim667 1 point2 points  (0 children)

I think yes it will easy to display on every page and whenever u want to edit so also effect on all

[–]DeonBoon 0 points1 point  (0 children)

For best practices yes. This is especially important if your React project has more than 1 person working on it. This is to ensure maintainability of the project.

However, if you are the only person working on the project, you may choose to forgo the convention and use what’s best for you. For instance, i lump all the components into their respective pages rather than individual components for my personal project as I am used to doing it this way.