https://overreacted.io/writing-resilient-components/
Linter is your friend. With a good config, a linter is a great tool to catch bugs before they happen.
But what about formatting? Use Prettier
- Don't stop the data flow in rendering.
- Read the props directly in your component and avoid copying props (or anything computed from the props) into state.
- Use useMemo to memoize expensive computations.
- Don't stop the data flow in side effects.
- Use useEffect to track side effect dependencies.
- Don't stop the data flow in optimizations.
- With useCallback and useContext, you can avoid passing functions deep down altogether. This lets you optimize rendering without worrying about functions.
- Component shouldn’t break just because it or its parent re-renders more often
- Even if a component is rendered just once, your design will improve if rendering twice doesn’t break it.
- Think about which state is local to a particular UI representation — and don’t hoist that state higher than necessary.