React Guidelines
Imports
A common way to sort the imports in the file is by their source: external
, absolute
, relative
separated by an empty line. Each of those groups can be sorted by line length, but that's not super important.
File structure
Inherits AirBnb naming convention https://github.com/airbnb/javascript/tree/master/react#naming
Use PascalCase for React components and camelCase for their instances
Naming convention react components
Pascal cased file names src/components/GenericForm.tsx
Filename and default component of the file should have the same name.
Naming convention non react components
Camel cased file names src/utils/hooks/useUser.ts
Naming convention folders
Lowercase kebab cased folders src/components/common/password-reset/ResetForm.tsx
Naming convention pages
Lowercase kebab cased files located in src/pages/sample-page.tsx
which correspond to /sample-page
url.
Types
The common convention is that the main type of the component's props is called after the component itself with suffix -Props
. Prop types of AdvancedForm
becomes AdvancedFormProps
.
Components
Nice IDE support and readability
Alternative export styles
Named function
Const arrow function
Discouraged as hooks cannot be used inside the class components
Styles
There are three common ways to style a component:
Styles using the <Box />
component
<Box />
componentSingle component that inherits all sizing props from MUI https://material-ui.com/system/basics/#all-inclusive
Styles using useStyles()
hook
useStyles()
hookStyles using SCSS files
Next.js supports SCSS out of the box. Read more at https://nextjs.org/docs/basic-features/built-in-css-support#sass-support
File convention is based on a suffix .module.scss
(ex. about.module.scss
)
Last updated