Browse Source

Clarify render prop caveat

main
Billy Janitsch 7 years ago
parent
commit
f57b73da2b
  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