Member-only story
React: How to prevent components from re-rendering?
Please SUBSCRIBE my YouTube Channel: FrontEnd Interview Preparation: https://www.youtube.com/channel/UC-elmWUfbcbmvuhlS12nCtg
This is one of the most frequently asked questions,
- shouldComponentUpdate() — returns ‘true’ by default. You can override if you know which props have to trigger an update.
- PureComponents — The difference between them is that
React.Component
doesn’t implementshouldComponentUpdate
method butReact.PureComponent
implements it with a shallow prop and state comparison. - React.memo — The same as the previous one but it works with functional components.
Keep learning, Keep growing!
Let’s connect on LinkedIn!