Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Question: "How does React.

memo() work, and why shouldn't it be used in every


component?"

Answer:

React.memo() optimizes performance by memoizing functional component results,


reducing unnecessary re-renders.
Indiscriminate use of React.memo() on every component may introduce performance
overhead, increased memory usage, and code complexity.
Strategically apply React.memo() to components that render frequently, receive
complex props, or are pure to achieve performance gains.
Before applying memoization, it's crucial to profile and measure performance to
ensure effective optimization.

use React.memo() with <div> instead of <> beacuse <> triggers rerender of all the
elements as it is do not add extra nodes to the DOM. whereas in case of div the
rerender only happends to the data which changes

You might also like