When to use some of the lifecycle methods in React

componentDidMount Add event listeners or any setup requires DOM Can call setState()
componentWillReceiveProps(nextProps) Act on certain prop changes e.g. redraw a Canvas Can call setState() and access to this.props
componentDidUpdate Updating a DOM after a prop or state change e.g. redraw Masonry grid Can call setState()
componentWilUnmount Cleaning up e.g. removing event listeners Can call setState()

Leave a Reply