React’s setState method with prevState argument

Posted by Jessica Taylor | Updated on

React’s setState method with prevState argument

Both signatures can be used, the only difference is that if you need to change your state based on the previous state you should use this.setState(function) which will provide for you a snapshot(prevState) from the previous state. But if the change does not rely on any other previous value, than a shorter version is recommended this.setState({prop: newValue})


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers