Store Utilities

produce

Edit this page

produce is an Immer inspired API for Solid's Store objects that allow for localized mutation.

import { produce } from "solid-js/store"
import type { NotWrappable, Store } from "solid-js/store"
function produce<T>(
fn: (state: T) => void
): (
state: T extends NotWrappable ? T : Store<T>
) => T extends NotWrappable ? T : Store<T>;

For use with createStore:

import { produce } from "solid-js/store";
const [state, setState] = createStore({
user: {
name: "John",
age: 30,
},
list: ["book", "pen"],
});
setState(
produce((state) => {
state.user.name = "Jane";
state.list.push("pencil");
})
);
Report an issue with this page