-
Notifications
You must be signed in to change notification settings - Fork 46.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
Is it intended that React.memo() also works with class components? #13937
Comments
Yeah we should probably document that it works with classes. It's intended to work with any valid component (including more exotic ones like |
Does this obsolete |
Not immediately, I think |
PureComponent is optimized for classes. It’s less optimized than pure + function. |
I'll close since it's intentional. Feel free to adjust docs in https://github.com/reactjs/reactjs.org. |
Do you want to request a feature or report a bug?
Clarification in the documentation, or more strict input validation.
What is the current behavior?
Currently,
React.memo()
is documented to receive a functional component, but it actually works correctly even if given a class component. I discovered this while looking into the code for writing the types in DefinitelyTyped/DefinitelyTyped#29990.The following code demonstrates that it works (both the rendering and the
console.log(ref)
):What is the expected behavior?
Only functional components are documented as valid arguments, so either class components should also be documented as supported, or React.memo should reject the argument.
The text was updated successfully, but these errors were encountered: