Concept Flow - React.memo usage
Component receives props
React.memo compares new props
Skip re-render
Update DOM if needed
React.memo checks if props changed. If not, it skips re-render to save work.
const MyComponent = React.memo(({ count }) => { console.log('Rendered:', count); return <div>{count}</div>; }); <MyComponent count={1} /> <MyComponent count={1} /> <MyComponent count={2} />
| Step | Props Received | Props Compared | Render Occurs? | Console Output |
|---|---|---|---|---|
| 1 | { count: 1 } | No previous props | Yes | Rendered: 1 |
| 2 | { count: 1 } | Compare with { count: 1 } | No | |
| 3 | { count: 2 } | Compare with { count: 1 } | Yes | Rendered: 2 |
| Variable | Start | After 1 | After 2 | After 3 |
|---|---|---|---|---|
| props.count | undefined | 1 | 1 | 2 |
| rendered | false | true | false | true |
React.memo is a function that wraps a component. It compares new props with previous props. If props are equal, it skips re-rendering. This improves performance by avoiding unnecessary updates. Use it for functional components that render the same output for same props.