Store utilities

storePath

Edit this page
import { storePath } from "solid-js/store"
function storePath(...args: any[]): (draft: any) => void

storePath() is a compatibility helper that adapts Solid 1.x-style path argument setters into a function you can pass to the Solid 2.0 draft-first setStore.


Usage

import { createStore } from "solid-js/store"
import { storePath } from "solid-js/store"
const [store, setStore] = createStore({
user: { address: { city: "London" } },
items: ["a", "b", "c"],
})
// 2.0 preferred: draft-first setter
setStore((s) => {
s.user.address.city = "Paris"
})
// Optional compat: 1.x-style path setter via storePath
setStore(storePath("user", "address", "city", "Paris"))

Path patterns

storePath supports the same patterns as Solid 1.x path setters:

Index access

setStore(storePath("items", 0, "newValue"))

Range

setStore(storePath("items", { from: 1, to: 4, by: 2 }, 99))

Filter

setStore(storePath("tasks", (task) => task.id === id, "completed", true))

Delete sentinel

setStore(storePath("nickname", storePath.DELETE))

When to use

Use storePath for gradual migration from Solid 1.x. For new code, prefer the draft-first setter pattern:

// Preferred
setStore((s) => {
s.user.address.city = "Paris"
})
Report an issue with this page