-
Notifications
You must be signed in to change notification settings - Fork 47.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DevTools Bug]: The memo component is not displayed correctly #32485
Comments
Fix Issue #32485 To properly prevent re-renders of B, ensure that: B is wrapped in memo (which you already did). "use client"; const A = memo(function A() { // Memoized A A ;}); const B = memo(function B() { B ;}); function App() { return ( export default App; |
"use client"; // Memoized Component A A ;}); // Memoized Component B B ;}); function App() { return ( export default App; Optimizing React Components with memo()1. JSX Return IssueIn the previous code, the return <div>A</div>;
return <div>B</div>; 2. Memoization and Re-rendersThe 3. Strict Mode and Double RenderingReact Strict Mode, which is enabled by default in some setups, intentionally renders components twice in development to help detect side effects. This can create confusion when testing performance optimizations like npm run build && npm start Alternatively, disabling Strict Mode in import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
ReactDOM.createRoot(document.getElementById("root")).render(
<App /> // Remove <React.StrictMode> to prevent double renders
); 4. Ensuring Optimization WorksTo confirm that <B value="fixed" /> can help test whether it re-renders when Final ThoughtsBy ensuring correct JSX syntax, understanding how |
I tested it and it has nothing to do with strict mode |
@spencer17x
However, if you later try to set B.displayName = 'B' after the declaration, it won't show up correctly in React DevTools. This is because memo essentially wraps the component, and after memoizing, React DevTools doesn't directly reference the original function name, so it doesn’t use the manually set displayName. The name assigned through the memoization process is the one React DevTools will display. Work around:
issue-32485.mp4 |
I think maybe devtools should fix it? |
I reckon an improved documentation with best practices would be a reasonable solution as well. |
Website or app
None
Repro steps
When displayName is used, the memo component will be displayed without 🧠.
How often does this bug happen?
Every time
DevTools package (automated)
No response
DevTools version (automated)
No response
Error message (automated)
No response
Error call stack (automated)
Error component stack (automated)
GitHub query string (automated)
The text was updated successfully, but these errors were encountered: