useSessionStorageState API
API reference for the useSessionStorageState hook.
Import
import useSessionStorageState from '@toolpad/core/useSessionStorageState';
// or
import { useSessionStorageState } from '@toolpad/core';
Learn about the difference by reading this guide on minimizing bundle size.
Reference
useSessionStorageState
const [state, setState] = useSessionStorageState('my-key', 'initial value');
Parameters
key:string | nullThe key under which to store the value inwindow.sessionStorage.initialValue:T | null | () => TThe value to return when nothing is found for thekeyinwindow.sessionStorage. 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 tuple where the first item represents the state, and the second item a setter for the state.