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.