ReactJS - Guideline
ReactJS - Guideline
1 NAMING CONVENTIONS
Header.js
HeroBanner.js
CookieBanner.js
Footer.js
myUtilityFile.js
cookieHelper.js
fetchApi.js
1.3 Unit test files should use the same name as its corresponding file
HeroBanner.js
HeroBanner.test.js
CookieBanner.js
CookieBanner.test.js
Header.css
CookieBanner.css
1.5 If a component requires multiple files (css, test) locate all files within component a folder
className
onClick
React doesn’t have any preferences in this regard. There are a few common approaches popular in
the ecosystem we may want to consider.
2.1 Grouping by Features or Routes
One of the common approache to structure projects is to locate CSS, JS, and tests together inside
folders grouped by feature or route.
3 CODE
To create a new React App follow the React’s recommended standard steps, please check.
https://reactjs.org/docs/create-a-new-react-app.html
Put all imports in order at the very top of the code file.
Make sure all your imports statements are on new lines.
Imports
Types (if required)
Styles (if required)
Additional variables
Component
- Definitions
- Functions
- Effects
- Additional destructures
Exports
Use index.js for each folder to export so that all the imports are referenced on the index.js file.
3.4 Usage of Double Quotes (" ") & Single Quotes (' ')
To avoide the confusion about double quotes (" ") & single quotes (' '), use double quotes (" ") for
JSX attributes and single quotes (' ') for the JS code.
3.14 Split code into respective files, JavaScript, test, and CSS
3.15 Avoid multiple if-else blocks. Instead, use ternary - best for clean code practice
3.17 Use/Create Custom Hooks instead of just putting a useEffect or multiple useStates directly to
your component
3.18 Avoid huge components, split your component into smaller chunks