React.memo: Shallow Comparison, Not Render Lock

React.memo does NOT stop re-renders. Even if props don’t change. State update? → Re-render. Context update? → Re-render. React.memo only compares props. That’s it. It’s not a render lock. It’s not magic. It’s a shallow comparison. If your memoized component still re-renders… That’s expected. Stop assuming. Start understanding. Did you know this before today? #react #javascript #frontend #webdev #performance

  • Dark-themed code screenshot titled “memo.js” showing a React functional component wrapped with React.memo. The component receives a title prop, uses useState to manage a count value, and uses useContext to access ThemeContext. A useEffect hook logs “Rendered” to the console. A button triggers a state update using setCount, demonstrating that the component re-renders despite being memoized. An annotation on the right highlights that changes in internal state or context will re-render the component. The image illustrates that React.memo only performs shallow comparison on props and does not prevent re-renders caused by state or context updates. ~ By Keshav Tiwari SDE Software Developer

Small nuance: React.memo only blocks re-renders caused by parent prop changes. It does NOT block: Internal state updates Context updates That’s where most confusion happens. Do you actually use the Profiler before adding memo?

To view or add a comment, sign in

Explore content categories