Open History to see the last commit
1import * as Solid from 'solid-js'
2β
3export function useSessionStorage<T>(key: string, initialValue: T) {
4 const stored = sessionStorage.getItem(key)
5 const [state, setState] = Solid.createSignal<T>(
6 stored ? JSON.parse(stored) : initialValue,
7 )
8β
9 Solid.createEffect(() => {
10 sessionStorage.setItem(key, JSON.stringify(state()))
11 }, [state()])
12β
13 return [state, setState]
14}