v6.0.0
This release has breaking changes!
Migrating from 5.x to 6.x
The 6.0 release includes breaking changes to what useSubstate
returns, as well as the removal of the Immer "patch" support that was previously exposed via usePatchEffect
. The globalDispatch
function has also been renamed to just dispatch
.
useSubstate
Where you previously had something like:
const [test, dispatch] = useSubstate(substates.test)
Or as was often the case in larger applications:
const [test, dispatchTest] = useSubstate(substates.test)
You will instead use the clearer and less error-prone syntax of:
const test = useSubstate(substates.test)
To get the current value of a substate, use:
test.current
And to get the Substate-specific dispatch function, use:
test.dispatch(...)
If you really want to still destructure these into {current: test, dispatch}
you can, however this is not the recommended approach.
useGlobalDispatch
Where you previously had something like:
const globalDispatch = useGlobalDispatch()
You will instead use:
const dispatch = useDispatch()
usePatchEffect
This hook has been removed and there is no planned replacement for it. If you still need its functionality, use v5.x instead.
TypeScript enhancements
The typing of React Substate is now better ar preventing users from doing the "wrong thing" by carrying forward types from Substate definitions all the way through to Actions verbatim and no longer widening types when additional properties are provided to either drafts or payloads.
Full Changelog: v5.3.3...v6.0.0