Syntax: We can use setState() to change the state of the component directly as well as through an arrow function. Example 1: Updating single attribute. We set up our initial state value inside constructor function and create another function updateState() for updating the state .24 Mar 2021
Read moreHow do I get Prev state in setState?
prevState() is the same as the setState but the only difference between them is that if we want to change the state of a component based on the previous state of that component, we use this. setState() , which provides us the prevState .
Read moreHow do I use previous state in setState React?
If you are going to calculate the state based on the previous state, you have to make sure you have the last and most up to date value , so they made setState() accept a function that is called with prevState and props, so you can have the correct value to update your state, like the example below.
Read more