Converts an object that changes on re-render to a reactive object that maintains the same instance across re-renders.
The converted object is only shallowly reactive and is readonly.
This hook converts data in React's reactivity system to reactive data that is compatible with the rest of this
library. You should use other hooks to create reactive data from source if possible, but if not, you can use this
hook to convert the data. A typical use case is to pass values from useState hooks or React contexts into this
function so that reactive effects, such as useEffect, can react to data changes from those hooks. You can also
use this hook to create reactive props if the component is not already wrapped with makeReactive.
Example
Converting a value from useState to a reactive object. Note that a better solution is to replace useState with
hooks such as useReactive if possible. This example is for illustration purpose only.
// Inside a function component: const [count, setCount] = useState(0); conststate = useReactiveRerender({ count });
Converts an object that changes on re-render to a reactive object that maintains the same instance across re-renders. The converted object is only shallowly reactive and is readonly.
This hook converts data in React's reactivity system to reactive data that is compatible with the rest of this library. You should use other hooks to create reactive data from source if possible, but if not, you can use this hook to convert the data. A typical use case is to pass values from
useState
hooks or React contexts into this function so that reactive effects, such asuseEffect
, can react to data changes from those hooks. You can also use this hook to create reactive props if the component is not already wrapped withmakeReactive
.Example
Converting a value from
useState
to a reactive object. Note that a better solution is to replaceuseState
with hooks such asuseReactive
if possible. This example is for illustration purpose only.Example
Creating reactive props. Components wrapped with
makeReactive
already have reactive props, so you don't need this hook in those components.Returns
A reactive object that maintains the same instance across re-renders.