mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
Clarify render prop caveat
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user