3 ms·
To me, the core problem with using two hooks is that there's no signal to other developers that the two pieces of state must be updated atomically. Sequential s
by jakelazaroff 5y ago
To me, the core problem with using two hooks is that there's no signal to other developers that the two pieces of state must be updated atomically. Sequential setState calls might be batched, but there's nothing preventing someone from only calling one of them.
- steve_adams_86 5y agoI'm not sure I understand. Which two hooks would be called in this case? In the original example I'm seeing where there's anything atomic involved across multiple hooks. Are you referring to the usePromise and useAsyncExtendedState? If so, it's okay to use those hooks independently. They work fine without each other, but they also work well together.
- jakelazaroff 5y agoI’m saying that if you have multiple pieces of state that must be updated atomically, it makes sense to store them in an object in one useState hook because it signals to other developers that they should be updated together. The fact that React allows you to batch the renders if you store the state in two separate hooks is unimportant.