Store utilities

snapshot (unwrap)

Edit this page

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>): T

Usage

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 serialization
const 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 libraries
fetch("/api/save", {
method: "POST",
body: JSON.stringify(snapshot(state)),
});
Report an issue with this page