If you have one variable it can be state === 'LOADING' or state === 'ERROR', never both. With two booleans you could have loading === true and error === true which could potentially be problematic.
So in your case, the loading and error states are mutual exclusive meaning they wont overlap. Because of this you can save on memory and rendering with one useState. Usually most components should only use one to two use states, any more and one should think about using useReducer, since multiple use states could trigger a bunch of unnecessary rerenders or a circular rerender loop if used improperly.
View all comments
Show parent comment
6
u/TwiliZant Feb 23 '20
Can you explain why this would be better?