Flesh out the basics of the most common methods

This commit is contained in:
Timothy Warren 2018-04-06 15:13:49 -04:00
parent df351f55cc
commit 910007114c
1 changed files with 55 additions and 0 deletions

View File

@ -45,17 +45,72 @@ static getDerivedStateFromProps (nextProps, prevState) {
#### componentDidMount () #### componentDidMount ()
```js
/**
* Component mounted, will render soon
*/
componentDidMount () {
// Network calls, state changes,
// anything is fair game here
}
```
## Updating ## Updating
#### shouldComponentUpdate () #### 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 () #### render ()
```js
/**
* Render returned components
*
* @return {React Element | string | number | Portal | null | boolean}
*/
render () {
return <div />;
}
```
#### getSnapshotBeforeUpdate () #### getSnapshotBeforeUpdate ()
```js
getSnapshotBeforeUpdate (prevProps, prevState) {
}
```
#### componentDidUpdate () #### componentDidUpdate ()
```js
componentDidUpdate (prevProps, prevState, snapshot = undefined) {
}
```
## Unmounting ## Unmounting
#### componentWillUnmount () #### componentWillUnmount ()
```js
componentWillUnMount () {
// Cleanup whatever you need to before the
// component unmounts
}
```
--- ---
## Deprecated ## Deprecated