Skip to main content
added 21 characters in body
Source Link
0stone0
  • 45.6k
  • 6
  • 54
  • 82

Since useStateuseState is async direct replacement of state is not a good idea. so it is better to access the previous state and set new updated value.

for exexample: setState((prev)=>[...prev, ...result]); //result is array of objects

setState((prev) => [...prev, ...result]);
//result is array of objects 

Since useState is async direct replacement of state is not a good idea. so it is better to access the previous state and set new updated value.

for ex: setState((prev)=>[...prev, ...result]); //result is array of objects

Since useState is async direct replacement of state is not a good idea. so it is better to access the previous state and set new updated value.

for example:

setState((prev) => [...prev, ...result]);
//result is array of objects 
Source Link

Since useState is async direct replacement of state is not a good idea. so it is better to access the previous state and set new updated value.

for ex: setState((prev)=>[...prev, ...result]); //result is array of objects