snapshot (unwrap)
Edit this pagecaution
In Solid 2.0, unwrap has been renamed to snapshot. The snapshot(store) function produces a non-reactive plain value suitable for serialization, logging, or passing to external libraries that do not understand Solid's reactive proxies.
snapshot returns a non-reactive, plain JavaScript copy of the store's data without the reactive proxy wrapper.
import { snapshot } from "solid-js/store"import type { Store } from "solid-js/store"
function snapshot<T>(store: Store<T>): TUsage
import { createStore, snapshot } from "solid-js/store";
const [state, setState] = createStore({ user: { name: "John", age: 30 }, items: ["book", "pen"],});
// Get a plain, non-reactive copy for serializationconst plain = snapshot(state);console.log(JSON.stringify(plain));// {"user":{"name":"John","age":30},"items":["book","pen"]}
// Useful for passing store data to external APIs or librariesfetch("/api/save", { method: "POST", body: JSON.stringify(snapshot(state)),});note
The returned value is a plain JavaScript object/array and is no longer reactive. Mutations to the snapshot will not update the store or trigger any reactive computations.