Skip to main content

useLocalStorage

Callable

  • useLocalStorage<T>(key: string, initialValue: ExcludeFunction<T>, options?: any): readonly [unknown, { resetStorage: () => void; setStorage: (value: unknown) => void }]

  • Returns a hook that provides a way to read from and write to the localStorage of the browser.


    Type parameters

    • T

    Parameters

    • key: string

      The key to use when reading/writing from/to localStorage.

    • initialValue: ExcludeFunction<T>

      The initial value to use when the key is not found in localStorage.

    • optionaloptions: any

      Optional configuration options for the hook.

    Returns readonly [unknown, { resetStorage: () => void; setStorage: (value: unknown) => void }]