From 910007114c3567594f049f43a5223598123b1e89 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 6 Apr 2018 15:13:49 -0400 Subject: [PATCH] Flesh out the basics of the most common methods --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index 71ddefe..de45993 100644 --- a/README.md +++ b/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
; +} +``` #### 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