@wojtekmaj/react-hooks
Version:
A collection of React Hooks.
8 lines (7 loc) • 343 B
TypeScript
/**
* Returns a stateful value synchronized with sessionStorage, and a function to update it.
*
* @param {string} key sessionStorage key
* @param {*} initialState Initial state
*/
export default function useSessionStorage<T = unknown>(key: string, initialState?: T | (() => T)): [T, (nextValueOrFunction: T | ((value: T) => T)) => void];