React
Basic Rules
Naming of Files and Folders
Conventional folders such as models, common, components, or core (which also contain only one word) should be in lowercase.
Conventional files like types.ts, interfaces.ts (which also contain only one word) should be entirely in lowercase.
File names within the component folder, such as style sheets, tests, or the component itself, should be written in UpperCamelCase.
Include Only One React Component Per File
Always use camelCase for prop names.
Always Use TSX Syntax
Do:
Don't:
Do Not Use Unless Initializing the Application from a Non-TSX File
Do:
Don't:
Avoid Using DOM Component Prop Names for Different Purposes
But it's possible to extend the props of the surrounding tag that has React, so the parent component can customize the attributes of the same.
Organize Files Related to the Same Component in a Folder
For example, if you have a component called "Carousel," all files related to "Carousel" (such as Carousel.jsx, Carousel.css, Carousel.test.js, etc.) should be in a folder named "Carousel".
If readability and the principle of single responsibility require decomposing the main component into child components and these are only used within that component, create a folder of components that contain components exclusively used by the main component, the same applies for constants, types, interfaces, utils, etc.
Example folder structure:
Always Use camelCase for Prop Names
Always Define Explicit defaultProps for All Unnecessary Props
Last updated