loading...

re: 3 React Mistakes Junior Developers Make With Component State VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Good question! I should clarify my article to help explain that better. You should use a function of the previous state when you are updating the ...
 

As an update, I updated the article just now to hopefully be more clear.

I changed the header text to:

Setting state that relies on the previous state without using a function

And I added this paragraph at the end of the section:

The key here is that if your new state relies on the value of the old state, you should always use a function as the argument. If you are setting a value that does not rely on the value of the old state, then you can use an object as the argument.

code of conduct - report abuse