DEV Community

Discussion on: Custom React Hooks: useBoolean

iamludal profile image
Ludal 🚀 Author • Edited on

It is a good practice to use the "function" form since the new value depends on the previous statue value. In most cases, both solutions will work correctly, but it is possible to have some kind of desynchronization (and so unexpected behaviors) when using your version.

A few keys here (though it is not exactly the same question as you) :

fidaay profile image

That "desynchronization" occurs because of states mutations are asynchronous, and it shouldn't be treated as a problem nor unexpected behavior.