Trigger a Side Effect with setState
A React component's setState function accepts a callback as an optional second argument. You can use this function to trigger side effects after setting state.
this.setState({ clickCounter: clickCounter + 1}, () => console.log('Click recorded!'));
Tweet