React Cheatsheet — this.setState()

Choose the correct lifecycle method

You can and should use this.setState() in only these React lifecycle methods: componentDidMount , componentDidUpdate and componentWillReceiveProps . You can also set it in the componentWillMount method, but it’s recommend to use the constructor instead.

New in React 16, you can also set it in componentDidCatch .