From ac10319fd577a69c93f5ac3ed07bb27ae2e3bb1c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 6 Apr 2018 15:01:51 -0400 Subject: [PATCH] Add more methods, flesh out getDerivedStateFromProps --- README.md | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6429f43..61de252 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Short reference of React.Component lifecycle methods so I don't have to scroll t ## Mounting -### constructor () +#### constructor () ``` /** @@ -22,12 +22,43 @@ constructor (props) { } ``` -### static getDerivedStateFromProps () +#### static getDerivedStateFromProps () + +``` +/** + * Props have changed, return the updated state + * + * @param {object} nextProps - Props for the next render + * @param {object} prevState - State from previous render + * @return {object | null} - The change to the state + */ +static getDerivedStateFromProps (nextProps, prevState) { + // Nothing to update + return null; + + // Set new state + return { + foo: 'foobar' + }; +} +``` + +#### componentDidMount () ## Updating -### shouldComponentUpdate () +#### shouldComponentUpdate () +#### render () +#### getSnapshotBeforeUpdate () +#### componentDidUpdate () ## Unmounting -### componentWillUnmount () \ No newline at end of file +#### componentWillUnmount () + +--- +## Deprecated + +### UNSAFE_componentWillMount () +### UNSAFE_componentWillReceiveProps () +### UNSAFE_componentWillUpdate () \ No newline at end of file