-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Write docs for React.PureComponent #7379
Comments
The most confusing thing for me: "Pure component" = functional stateless component, doesn't extend a class |
@kevinSuttle wait... |
Yeah, it'd be great to have some docs about this topic. Do Functional Components implement by default the same logic as
|
That's not the case. It's effectively just a base class to extend with PureRenderMixin built in. This is why we need docs 😉 |
Hello Guys! I think we don't have a docs, so... I have one question! If I have a dump component, that only render something. It's better to use the stateless component, or a class that extends PureComponent? Thanks ;) |
@raphaguasta |
@raphaguasta @cbengtson85 according to this code the main difference between PureComponent and StatelessComponent:
So in your case shouldUpdate value will be false for PureComponent and true for StatelessComponent. I think it's cheaper to make shallow equality check than making a Virtual DOM comparison, but I may be wrong here. |
It is in the docs now. |
Thanks a lot for adding some docs about However, it's still obscur to me when use or not use it. Most of components are tied to their props and state, thus the majority of Component should be extending PureComponent? When using React component with Redux for example. Also, I always wrote my component as StatelessComponent. But it seems that PureComponent can also be a more efficient than a StatelessComponent, as @frandsaw stated, a shallow equality check may be cheaper than a virtual dom comparison. So my conclusion right now is "PureComponent all the things!", but I fear I may be missing something here… If you have some good examples where Component or StatelessComponent is better than a PureComponent, it would be great! Thanks a lot for your help 👍 |
If something is slow then try using There is no sure way to tell which is going to be slower: reconciliation or shallow comparisons everywhere. In pathological cases (shallow equality checks often failing) |
Thank you @gaearon for your response, it helps! |
I wish there would be at least one example somewhere in docs that you can copy-paste instead of historical perspective on what was changed and what add-ons were deprecated :) I can still copy-paste code for old add-ons from the docs! why can't I get new stuff? |
I'm not sure what you mean. If I open "Optimizing Performance", it has a code example. Are you looking at some different page? |
I wrote a simple blog post explaining PureComponent. Hope it helps! https://ashishchaudhary.in/using-purecomponent-to-prevent-wasted-renders-in-react |
I saw many people misusing |
Need to at least update the top level api page, but should consider writing something more about it.
cc @spicyj
The text was updated successfully, but these errors were encountered: