The setState
method is used to update a single state variable at a time. Is this statement True or False. If true, why?
I’m confusing about that statement. It can also update a single state variable also or only it can update multiples values.
please clarify me about that statement
2
Answers
The
setState
can update the entire state of the component. Let’s say you have a component:Using the
setState
method you can update 1,2 or all 3 state variables by calling it:So yes the setState accepts only 1 input argument, but that input argument is the object representing the entire state of the component
It is true, but then your variable could be a list or an object, and contain "inner-variables" if that makes sense.
Also you can call setState multiple time, it’s just the way to hook events in modern web clients.