Skip to content

Instantly share code, notes, and snippets.

@swapnilmishra
Last active December 8, 2016 08:06
Show Gist options
  • Save swapnilmishra/5b852d461dc4b31f92642518d92416dc to your computer and use it in GitHub Desktop.
Save swapnilmishra/5b852d461dc4b31f92642518d92416dc to your computer and use it in GitHub Desktop.
1. The render() function should be pure, meaning that it does not modify component state,
it returns the same result each time it's invoked, and it does not directly
interact with the browser. If you need to interact with the browser,
perform your work in componentDidMount() or the other lifecycle methods instead.
Keeping render() pure makes components easier to think about.
2. componentWillMount() - This is the only lifecycle hook called on server rendering.
Generally, we recommend using the constructor() instead.
3. componentDidMount() is invoked immediately after a component is mounted.
Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint,
this is a good place to instantiate the network request. Setting state in this method will trigger a re-rendering.
4. componentWillUpdate() - Note that you cannot call this.setState() here.
If you need to update state in response to a prop change, use componentWillReceiveProps() instead.
5. componentDidUpdate() - Use this as an opportunity
to operate on the DOM when the component has been updated. This is also a good place to
do network requests as long as you compare the current props to previous props
(e.g. a network request may not be necessary if the props have not changed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment