Skip to content

Add React.PureComponent to documentation #7730

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions docs/docs/10.8-pure-render-mixin.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: pure-render-mixin
title: PureRenderMixin
title: PureRenderMixin and React.PureComponent
permalink: docs/pure-render-mixin.html
prev: update.html
next: perf.html
Expand All @@ -21,24 +21,18 @@ React.createClass({
});
```

Example using ES6 class syntax:
Under the hood, the mixin implements [shouldComponentUpdate](/react/docs/component-specs.html#updating-shouldcomponentupdate), in which it compares the current props and state with the next ones and returns `false` if the equalities pass.

```js
import PureRenderMixin from 'react-addons-pure-render-mixin';
class FooComponent extends React.Component {
constructor(props) {
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:
Copy link
Contributor

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.

Copy link
Contributor

@aweary aweary Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd also need to mention that PureComponent isn't exactly the same as pure-render-mixin, as it also affects the behavior of functional children. See #6914 for @spicyj's overview of what it does

Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

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


```js
class FooComponent extends React.PureComponent {
render() {
return <div className={this.props.className}>foo</div>;
}
}
```

Under the hood, the mixin implements [shouldComponentUpdate](/react/docs/component-specs.html#updating-shouldcomponentupdate), in which it compares the current props and state with the next ones and returns `false` if the equalities pass.

> Note:
>
> This only shallowly compares the objects. If these contain complex data structures, it may produce false-negatives for deeper differences. Only mix into components which have simple props and state, or use `forceUpdate()` when you know deep data structures have changed. Or, consider using [immutable objects](https://facebook.github.io/immutable-js/) to facilitate fast comparisons of nested data.
Expand Down