A better way to approach state in React.
I've found a few problems with the existing state solutions in functional components in React. Namely:
useStateanduseReducerdo not immediately update state. You have to useuseEffectto know when state has truly changed.useReduceris cumbersome to use to manage state. I've done it a million times and hated it every time.useStateis meant for primitive values, not complex, deeply nested objects.useContextis incredibly useful, but also requires a lot of boilerplate.
Hence, we have better-state! In better state, there will be a few hooks:
useListenerState: allows you to listen for state changes, either on the whole object or on a specific property.useAwaitState: lets you write code likeconst nextState = await setState({ ... })and be sure that the state has changed.useBetterState: the combination ofuseListenerStateanduseAwaitState, you get the best of both worlds.useSharedState: the granddaddy of them all, lets you use better-state across components.
More to come...