-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Possible issue in "Components and Props" section of docs - functional vs. class components #639
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
Comments
Functional components in React 16 don't go through the same code path as class components, unlike in previous version where they were converted to classes and would have the same code path. Class components have additional checks required and overhead in creating the instances that simple functions don't have. These are micro-optimizations though and shouldn't make a huge difference in real-world apps – unless your class component is overly complex. I've not benchmarked functional components vs class components with the latest version of React, but it would be interesting if someone did to see the differences today given the amount of tweaks that have happened in JS engines since I last benchmarked. |
Thanks @trueadm - very good to know, even though it's a just a micro-optimization. So it's as I said above - using PureComponent would make a much bigger difference. I still think both of these points should be mentioned in the docs. It's misleading to just say, "The above two components are equivalent from React’s point of view" and leave it at that. That introductory section isn't the right place to get into tiny nuances of performance differences, but it could have a link to a more advanced section with notes about performance. I might submit a PR. |
Going to close this as the docs are completely different now, and the performance note doesn't seem relevant in 2025. Also we recommend all components be function components in the docs already: https://react.dev/reference/react/Component |
The current documentation says:
I just encountered a contradictory comment from @trueadm, an engineer on the React core team:
https://medium.com/@trueadm/in-react-16-functional-components-are-quite-a-bit-faster-than-class-components-1afca4931d7c
Does this mean that the possible future optimizations for functional components that were mentioned in previous versions of the docs and blog posts have now been implemented? If so, this should be mentioned in the docs (and probably should have been in the release notes for React 16 too, but I don't see it mentioned there).
If this has indeed been implemented, then it should also be noted that this is a micro-optimization that still pales in comparison with using PureComponent (or your own efficient
shouldComponentUpdate()
logic), as explained in facebook/react#5677 (comment):The text was updated successfully, but these errors were encountered: