Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Created October 13, 2019 21:28
Show Gist options
  • Select an option

  • Save jasdeepkhalsa/1dd0ed984cee6e0114f1c6c137b22985 to your computer and use it in GitHub Desktop.

Select an option

Save jasdeepkhalsa/1dd0ed984cee6e0114f1c6c137b22985 to your computer and use it in GitHub Desktop.
React Hooks Transition Guide

setState -> const [state, setState] = useState()

componentDidMount -> useEffect(() => {}, [])

componentDidMount & componentDidUpdate -> useEffect(() => {}, [props.changedValue]

componentWillUnmount & componentDidUnmount -> useEffect(() => { return () => console.log('Cleaning up') }, [])

shouldComponentUpdate -> export default React.memo(myComponent, () => console.log('finer grain control here, but I work opposite to shouldComponentUpdate. Usually out of the box memoization is good enough')

Only use hooks in the top-level of your function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment