- Think in React
- Use only Function Components, no more Class Component
- Use custom hooks instead of HOC, replace withFoo by useFoo
- Use composition
- Use slots
- Use "as" prop to override an
Element
- Seperate the smart and dumb component
- Keep state as local as possible.
- Derive state, don't sync state, (you might not need an effect)[https://react.dev/learn/you-might-not-need-an-effect]
- Prefer state enums instead of booleans
- Use Storybook to code your components in isolation and enforce the separation of concern design pattern
- Use React Testing Library for testing your components and mimic users effects
- Use the Web Platform as much as possible
Read Managing State
When you want to coordinate two components, move their state to their common parent.
Then pass the information down through props from their common parent.
Finally, pass the event handlers down so that the children can change the parent’s state.
It’s useful to consider components as “controlled” (driven by props) or “uncontrolled” (driven by state).
If you are sure that useState
, useReducer
nor useContext
cannot meet your needs, then you can choose an external tool from the following list
Data Management :
State Management :
State Machine :
Deprecated :
- Redux & redux-saga
Hooks feature was introduced in React 16.8 that allow you to use state and other React features in functional components, which were previously only available in class components.
Hooks are functions that let you "hook into" React state and lifecycle features from function components. They provide a more direct API to the React concepts you already know.
Hooks make React components more functional and modular.
You can create your own Hooks to extract and share logic between components. Custom Hooks are a convention that naturally follows from the design of Hooks, rather than a React feature.
Forms are a crucial part of Web applications and the Web Platform offers many options for managing forms natively.
HTML5 validation features can cover a lot of your needs.
If you need more fine grained validation, most form-related tasks can be handle by hooks like useState
and useEffect
, see State Management).
If you are sure that useState
, useReducer
nor useContext
cannot meet your needs, then you can choose an external tool from the following list :
Resources :
- Use key to reset a state, ie for (reseting a form)[https://react.dev/learn/preserving-and-resetting-state#resetting-a-form-with-a-key]
- useId()
@TODO
Resources :
- (
<Profiler>
)[https://react.dev/reference/react/Profiler] - (compiler)[https://react.dev/learn/react-compiler]
@TODO @React19
@TODO @React19
@TODO @React19
Resources :
Resources :
Resources :