Clarify render prop caveat

This commit is contained in:
Billy Janitsch
2018-03-22 21:08:25 -04:00
parent 2793656257
commit f57b73da2b

View File

@@ -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.