React Reusability and Performance
React Reusability
In order to DRY, 4 design patterns have emerged in React:
- Components with props
- Children
- Higher Order Components
- Render props
React Performance
In order to prevent React from rendering the entire tree when a branch doesn't have its props and state changed, React has 3 ways:
shouldComponentUpdate()
: The oldest, replaced byPureComponent
PureComponent
: For class componentsmemo()
: for functional components
Avoid premature optimization.