modifyMutable
Edit this pagecaution
In Solid 2.0, modifyMutable has been removed from solid-js/store alongside createMutable. Both APIs have been moved to the @solidjs/signals package.
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.0import { 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): voidRecommended Alternative
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 automaticallysetState((draft) => { draft.user.firstName = "Jane"; draft.user.lastName = "Doe";});