How to solve the dependent state problem in React


In React-land, this is a pretty common problem: You have two useState variables, and when something happens, both variables must change, at once.

The key problem here being the “at once” part. You see, in React all state is asynchronous, so if we simply do:

setState1(true)
setState2(false)

We have no warrantee that state 2 is

Want updates on our latest blog posts?
Subscribe to our newsletter!

Previous Post
React mocking with the Repository Pattern
Next Post
A Kaleidoscope of Programming Languages: Lisp