0

Good evening!
So, I'm wondering if it's possible to chain useState() methods to execute "together" in a certain order. My guess is that they work in the same async way as this.setState, but with the last I can provide a function as second argument to kind of "chain" the state changes.

I can do, for an example:

this.setState({ running: false }, () => {
  this.setState({ resetScore: true })
});

So I know it will wait for the first setState before initializing the second.

But I noticed that useState() doesn't accept a second parameter... So how do I write that setState logic to hooks?

Thanks! :)

skyboyer
  • 19,620
  • 7
  • 50
  • 62
Zigoni
  • 25
  • 5

0 Answers0