@mocanvas/mocanvas · function

useLocalStorageState

declare function useLocalStorageState<T>(key: string, defaultValue: T): [T, (value: T) => void]

A value kept in localStorage, as React state.

Every access is guarded: localStorage throws outright in a sandboxed iframe and in a browser configured to block site data, and a panel that remembers whether a section was collapsed must not be the thing that takes the editor down.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.