@tremendous/help
    Preparing search index...

    Function useLocalStorage

    • Custom hook to manage state that is synchronized with localStorage.

      This hook provides a stateful value and a function to update it, while keeping the value in sync with localStorage.

      Type Parameters

      • T

        The type of the value to be stored.

      Parameters

      • key: string

        The key under which the value is stored in localStorage.

      • initialValue: T

        The initial value to be used if the key does not exist in localStorage.

      Returns [T, SetValue<T>]

      • Returns the current value and a function to update it.
      const [name, setName] = useLocalStorage<string>('name', 'Anonymous');
      setName('John Doe');