Browse Source

Code the `null` and `undefined` values (#3203)

main
李鸿章 4 years ago
committed by GitHub
parent
commit
b24cabac64
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      content/docs/reference-react-component.md

6
content/docs/reference-react-component.md

@ -274,7 +274,7 @@ Currently, if `shouldComponentUpdate()` returns `false`, then [`UNSAFE_component
static getDerivedStateFromProps(props, state)
```
`getDerivedStateFromProps` is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.
`getDerivedStateFromProps` is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or `null` to update nothing.
This method exists for [rare use cases](/blog/2018/06/07/you-probably-dont-need-derived-state.html#when-to-use-derived-state) where the state depends on changes in props over time. For example, it might be handy for implementing a `<Transition>` component that compares its previous and next children to decide which of them to animate in and out.
@ -587,7 +587,7 @@ Normally you should try to avoid all uses of `forceUpdate()` and only read from
### `defaultProps` {#defaultprops}
`defaultProps` can be defined as a property on the component class itself, to set the default props for the class. This is used for undefined props, but not for null props. For example:
`defaultProps` can be defined as a property on the component class itself, to set the default props for the class. This is used for `undefined` props, but not for `null` props. For example:
```js
class CustomButton extends React.Component {
@ -607,7 +607,7 @@ If `props.color` is not provided, it will be set by default to `'blue'`:
}
```
If `props.color` is set to null, it will remain null:
If `props.color` is set to `null`, it will remain `null`:
```js
render() {

Loading…
Cancel
Save