⚠️ ⚠️ ⚠️ v1.2.10 turns out to have some bugs. Please use v1.2.11 instead. The Migration Guide below is still valid.
This adds new proxyMap
and fixes derive
, both in valtio/utils
. The internal DeepResolveType
type is deprecated, which might require migration.
Migration Guide (from v1.2.8 and v1.2.9)
In case you need to specify snapshot types, there are two options.
Assert mutable (let's lie)
type State = { foo?: string }
const state = proxy<State>({})
const snap = useSnapshot(state) as State
const handleSnap = (s: State) => {
// ...
}
as State
can be as typeof state
.
Wrap types with Readonly<>
type State = { foo?: string }
const state = proxy<State>({})
const snap = useSnapshot(state)
const handleSnap = (s: Readonly<State>) => {
// ...
}
Readonly<State>
can be Readonly<typeof state>
If the state is deeply nested, please define DeepReadonly
type util.
type DeepReadonly<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
}
const handleSnap = (s: DeepReadonly<State>) => {
// ...
}
What's Changed
- feat(utils): add proxyMap by @fkhadra in #330
- fix: avoid const enum and deprecate DeepResolveType by @dai-shi in #333
- fix(utils): make derive glitch free by @dai-shi in #335
Full Changelog: v1.2.9...v1.2.10