-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Add React.PureComponent to documentation #7730
Conversation
super(props); | ||
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); | ||
} | ||
When using ES6 class syntax, you can instead use the `React.PureComponent` base class, which achieves the same result: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say "ES6 classes" instead and remove the comma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aweary the SFC heuristics didn't get included; see #7195 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old text used "ES6 class syntax", so I kept that the same for consistency. I can change it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ES6 class syntax" sounds weird to me, but I don't feel strongly either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should give PureComponent
it's own page in the documentation rather than just inserting it into the pure-render-mixin doc.
Are there any advantages to that? Conceptually it's the same thing as the PureRenderMixin. |
We should at least add this on the API reference page too, but this seems good by itself too. |
I didn't realize that the SFC heuristics weren't actually included yet, so at this point, it is conceptually the same thing, but long term it will diverge from PureRenderMixin in how it treats SFCs. So yeah, at this point this seems fine to me. |
Sorry for barging in. While this PR makes In a idiomatic react application, wouldn't the majority of your components extend *EDIT: I guess in an idiomatic react application the majority of your components would be pure functions, but the first part of my comment should still be valid. |
Update: added "no setState calls" clarification What is the difference between pure function and
vs
I think |
@shamrin One important difference is that the pure function is stateless, whereas |
@GGAlanSmithee I forgot to mention "no setState calls". I've updated my comment above. Do pure function components have the same optimisation as |
They do not, see this: https://jsfiddle.net/Daniel15/8t39ov1z/1/ |
Thanks for PR! We set up a separate place for |
Thank you Dan! :D |
Documents
React.PureComponent
on the PureRenderMixin documentation page.