Store utilities

modifyMutable

Edit this page

Migration

Update your imports from:

// Solid 1.x (no longer works in 2.0)
import { modifyMutable, reconcile, produce } from "solid-js/store";

To:

// Solid 2.0
import { modifyMutable } from "@solidjs/signals";
import { reconcile, produce } from "solid-js/store";

Previous Usage

modifyMutable streamlined the process of making multiple changes to a mutable Store, as obtained through the use of createMutable.

It operated within a single batch, ensuring that dependent computations are updated just once, rather than triggering updates for each individual change.

import { modifyMutable } from "@solidjs/signals";
function modifyMutable<T>(mutable: T, modifier: (state: T) => T): void

In Solid 2.0, the recommended approach for most use cases is createStore with its draft-first setter, which batches updates automatically:

import { createStore } from "solid-js/store";
const [state, setState] = createStore({
user: {
firstName: "John",
lastName: "Smith",
},
});
// Draft-first setter batches all mutations automatically
setState((draft) => {
draft.user.firstName = "Jane";
draft.user.lastName = "Doe";
});
Report an issue with this page