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:
useState
anduseReducer
do not immediately update state. You have to useuseEffect
to know when state has truly changed.useReducer
is cumbersome to use to manage state. I've done it a million times and hated it every time.useState
is meant for primitive values, not complex, deeply nested objects.useContext
is 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 ofuseListenerState
anduseAwaitState
, you get the best of both worlds.useSharedState
: the granddaddy of them all, lets you use better-state across components.
More to come...