useLocalStorageState API
API reference for the useLocalStorageState hook.
Import
import useLocalStorageState from '@toolpad/core/useLocalStorageState';
// or
import { useLocalStorageState } from '@toolpad/core';
Learn about the difference by reading this guide on minimizing bundle size.
Reference
useLocalStorageState
const [state, setState] = useLocalStorageState('my-key', 'initial value');
Parameters
- key:- string | nullThe key under which to store the value in- window.localStorage.
- initialValue:- T | null | () => TThe value to return when nothing is found for the- keyin- window.localStorage. The value can be lazy computed by providing a function to this parameter.
- options?:- objectAdditional options for this hook.- codec?:- Codec<T>A codec that can encode and decode values of type V to and from strings.- parse:- (raw: string) => TDecodes a string value into a value of type V.
- stringify:- (value: T) => stringEncodes a value of type V into a string.
 
 
Returns
[T | null, React.Dispatch<React.SetStateAction<T | null>>] Similar to React.setState result, it returns a tupple where the first item represents the state, and the second item is a setter for the state.