Today I Learned

A Hashrocket project

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!'));
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.