MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / createLocalStore

Function createLocalStore

examples/sandbox/src/Todos.tsx:4–15  ·  view source on GitHub ↗
(
    name: string,
    init: T,
)

Source from the content-addressed store, hash-verified

2import {createStore, produce, type SetStoreFunction, type Store, unwrap} from 'solid-js/store'
3
4export function createLocalStore<T extends object>(
5 name: string,
6 init: T,
7): [Store<T>, SetStoreFunction<T>] {
8 const localState = localStorage.getItem(name)
9 // const localState = undefined
10 const [state, setState] = createStore<T>(
11 localState ? JSON.parse(localState) as any : init, {name}
12 )
13 s.createEffect(() => localStorage.setItem(name, JSON.stringify(state)))
14 return [state, setState]
15}
16
17export function removeIndex<T>(array: readonly T[], index: number): T[] {
18 return [...array.slice(0, index), ...array.slice(index + 1)]

Callers 1

TodosFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…