Flesh out the basics of the most common methods
This commit is contained in:
parent
df351f55cc
commit
910007114c
55
README.md
55
README.md
@ -45,17 +45,72 @@ static getDerivedStateFromProps (nextProps, prevState) {
|
||||
|
||||
#### componentDidMount ()
|
||||
|
||||
```js
|
||||
/**
|
||||
* Component mounted, will render soon
|
||||
*/
|
||||
componentDidMount () {
|
||||
// Network calls, state changes,
|
||||
// anything is fair game here
|
||||
}
|
||||
```
|
||||
|
||||
## Updating
|
||||
|
||||
#### shouldComponentUpdate ()
|
||||
|
||||
```js
|
||||
/**
|
||||
* Hook to control re-render
|
||||
*
|
||||
* @param {object} nextProps
|
||||
* @param {object} nextState
|
||||
* @return {boolean} - Whether to render this cycle
|
||||
*/
|
||||
shouldComponentUpdate (nextProps, nextState) {
|
||||
// Default in React.Component
|
||||
return true;
|
||||
|
||||
// React.PureComponent implements this method
|
||||
// with a shallow compare of props and state
|
||||
}
|
||||
```
|
||||
#### render ()
|
||||
|
||||
```js
|
||||
/**
|
||||
* Render returned components
|
||||
*
|
||||
* @return {React Element | string | number | Portal | null | boolean}
|
||||
*/
|
||||
render () {
|
||||
return <div />;
|
||||
}
|
||||
```
|
||||
#### getSnapshotBeforeUpdate ()
|
||||
|
||||
```js
|
||||
getSnapshotBeforeUpdate (prevProps, prevState) {
|
||||
}
|
||||
```
|
||||
#### componentDidUpdate ()
|
||||
|
||||
```js
|
||||
componentDidUpdate (prevProps, prevState, snapshot = undefined) {
|
||||
}
|
||||
```
|
||||
|
||||
## Unmounting
|
||||
|
||||
#### componentWillUnmount ()
|
||||
|
||||
```js
|
||||
componentWillUnMount () {
|
||||
// Cleanup whatever you need to before the
|
||||
// component unmounts
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
## Deprecated
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user