Rehooks
Hooks

useSessionStorage

A React hook that allows you to persist data across browser sessions.

useSessionStorage

A React hook that allows you to persist data across browser sessions.

Usage

import { useSessionStorage } from "rehooks-ts";
 
const [value, setValue] = useSessionStorage("key", "defaultValue");

API

useSessionStorage

function useSessionStorage<T>(
  key: string,
  initialValue: T,
): [T, (value: T) => void];

Parameters

NameTypeDescription
keystringThe key of the item to be stored in session storage.
initialValueTThe initial value to be used if the item does not exist in session storage.

Returns

NameTypeDescription
valueTThe value of the item in session storage.
setValue(value: T) => voidA function that sets the value of the item in session storage.

On this page