Answer the question
In order to leave comments, you need to log in
How does setState work?
I can’t find such information on the work of setState: are the fields of the state object inside setState updated asynchronously with each other or not? And if you cause a change, for example, of the same field of the counter counter to +1 within one setState, will they be incremented asynchronously?
Answer the question
In order to leave comments, you need to log in
Duplicate properties in an object literal override each other. The value of the latter gets into the created object. Example.
So the object returned by the function call is:
prevState => ({
counter: prevState.counter + 1,
counter: prevState.counter + 1,
})
prevState.counter === 0
{
counter: 0 + 1,
counter: 0 + 1, // результат этого выражения попадет в созданный объект
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question