Answer the question
In order to leave comments, you need to log in
How to properly update the state of a component?
Let in the state of the component I have an array of users objects, where I want to add a new user. It's not entirely clear to me why you can't change state directly? And why, when executing setState(), make a copy of the users array, if only references to objects are copied to the new array anyway, and not the objects themselves? Just so that a reference to a new array appears in state and React detects the change?
Answer the question
In order to leave comments, you need to log in
More than a dozen articles have been written about the advantages and disadvantages of using immutable data updates. The React library uses this concept to track changes to the state and properties of components.
It is for this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question