React
From JavaScript Review
Go to text →
From Code Quality
Go to text →
- Single Responsibility
- Is the method/class responsible for one thing?
- Data Structures
- Can the data structure represent illegal states? Why?
- Use
Mapinstead ofObjectif possible!
- Do you really need
useCallback,useMemo? i.e. is it one of the following:- Is it used to memoize props of a memoized component?
- Is it used to memoize JSX sub-hierarchies that are expensive to render again?
- Is it used to memoize a very expensive operation (for most "normal" JavaScript the answer is "no"!)
- Do you really need
useEffect?useEffectlogic should run because the component was displayed and for no other reason, i.e.- sending an analytics request
- requesting data for the render (but make sure to add cleanup/ignore logic to make only the last request matter)
- When can just remove it and write it directly in the component:
- Calculating derived values from state/props
- Updating state when a prop changes
- Do you really need to do this? Maybe you can just calculate a derived value directly instead?
- When you can do something else instead:
- Resetting state on id/prop change?
- Pass a
keyto the component to the parent - to force re-initialization
- Pass a
- Trigger common logic from several event handlers
- Extract a common helper method instead and call that both times
- Do something once when the App starts
- Run it outside of a component instead
- Sync with an external store
- Use
useSyncExternalStorein React > 18
- Use
- Resetting state on id/prop change?
From UI Components
Go to text →