Browse Source

Merge pull request #700 from billyjanitsch/clarify-render-prop

Clarify PureComponent render prop caveat
main
Michael Jackson 7 years ago
committed by GitHub
parent
commit
425043533f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      content/docs/render-props.md

12
content/docs/render-props.md

@ -305,14 +305,8 @@ To get around this problem, you can sometimes define the prop as an instance met
```js
class MouseTracker extends React.Component {
constructor(props) {
super(props);
// This binding ensures that `this.renderTheCat` always refers
// to the *same* function when we use it in render.
this.renderTheCat = this.renderTheCat.bind(this);
}
// Defined as an instance method, `this.renderTheCat` always
// refers to *same* function when we use it in render
renderTheCat(mouse) {
return <Cat mouse={mouse} />;
}
@ -328,4 +322,4 @@ class MouseTracker extends React.Component {
}
```
In cases where you cannot bind the instance method ahead of time in the constructor (e.g. because you need to close over the component's props and/or state) `<Mouse>` should extend `React.Component` instead.
In cases where you cannot define the prop statically (e.g. because you need to close over the component's props and/or state) `<Mouse>` should extend `React.Component` instead.

Loading…
Cancel
Save