useShallowReadonly<T>(initialValue: T | (() => T)): Readonly<T>
The hook version of shallowReadonly from @vue/reactivity.
In addition to values accepted by shallowReadonly, you can also pass an initializer function returning the value.
This hook version allows the readonly ref to be created when the component first renders, then cached for future
re-renders.
If you pass in an initializer function, it will only be called on first render.
Unlike (), there is no deep conversion: only root-level
properties are made readonly. Property values are stored and exposed as-is -
this also means properties with ref values will not be automatically
unwrapped.
Example
// Inside a function component: conststate = useShallowReadonly(() => ({ foo:1, nested: { bar:2 } }))
// mutating state's own properties will fail state.foo++
// ...but works on nested objects isReadonly(state.nested) // false
The hook version of
shallowReadonly
from@vue/reactivity
. In addition to values accepted byshallowReadonly
, you can also pass an initializer function returning the value.This hook version allows the readonly ref to be created when the component first renders, then cached for future re-renders. If you pass in an initializer function, it will only be called on first render.
Shallow version of ().
Unlike (), there is no deep conversion: only root-level properties are made readonly. Property values are stored and exposed as-is - this also means properties with ref values will not be automatically unwrapped.
Example
See
https://vuejs.org/api/reactivity-advanced.html#shallowreadonly