React Memo

Utilizing React.memo helps optimize performance by skipping the re-rendering of a component if its props have not changed.

Tutorials dojo strip



Performance Optimization

By avoiding unnecessary re-renders, React.memo can boost your application’s performance.




Problem

Consider this example where the TaskList component re-renders even if the tasks haven’t changed.

index.js:

JS

TaskList.js:

JS

In this setup, clicking the increment button triggers a re-render of the TaskList component, even though the tasks haven’t changed. If this component were more complex, it could negatively affect performance.




Solution

To resolve this issue, we can use React.memo. Wrapping the TaskList component in React.memo prevents unnecessary re-renders.

index.js:

JS

TaskList.js:

JS
Tutorials dojo strip