Refractor docs to indicate that state set to props in constructor will not recieve the updated props (#9404)
hanumanthan committed
Apr 13, 2017 at 05:26 UTC
5cd44d21e9eb1e5014b9ae2109268600ce1c360f
1 file changed
+2
-2
docs/docs/reference-react-component.md
+2
-2
@@ -113,7 +113,7 @@ The constructor for a React component is called before it is mounted. When imple
113
114
The constructor is the right place to initialize state. If you don't initialize state and you don't bind methods, you don't need to implement a constructor for your React component.
115
116
-It's okay to initialize state based on props if you know what you're doing. Here's an example of a valid `React.Component` subclass constructor:
116
+It's okay to initialize state based on props. This effectively "forks" the props and sets the state with the initial props. Here's an example of a valid `React.Component` subclass constructor:
117
118
```js
119
constructor(props) {
@@ -124,7 +124,7 @@ constructor(props) {
124
}
125
```
126
127
-Beware of this pattern, as it effectively "forks" the props and can lead to bugs. Instead of syncing props to state, you often want to [lift the state up](/react/docs/lifting-state-up.html).
127
+Beware of this pattern, as state won't be up-to-date with any props update. Instead of syncing props to state, you often want to [lift the state up](/react/docs/lifting-state-up.html).
128
129
If you "fork" props by using them for state, you might also want to implement [`componentWillReceiveProps(nextProps)`](#componentwillreceiveprops) to keep the state up-to-date with them. But lifting state up is often easier and less bug-prone.
130