- React.memo is a higher-order component (HOC) in React that memoizes a component, meaning it will only re-render if its props have changed.
- This can improve performance by preventing unnecessary render calls, especially for components that are expensive to render.
Syntax:
1 2 3 4 5 6 7 8 9 10 |
import React from 'react'; let MyComponent =({ data }) => { // component implementation return ( // ...code ); }; export default React.memo(MyComponent ); |
In this example, MyComponent will only re-render if data changes.