Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/netzo/deps/usehooks-ts.ts>useLocalStorage

Full-stack Deno framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
Go to Latest
function useLocalStorage
import { useLocalStorage } from "https://deno.land/x/netzo@0.4.72/deps/usehooks-ts.ts";

Custom hook for using local storage to persist state across page reloads.

Examples

const [count, setCount] = useLocalStorage('count', 0); // Access the count value and the setCount function to update it.

Type Parameters

T
  • The type of the state to be stored in local storage.

Parameters

key: string
  • The key under which the value will be stored in local storage.
initialValue: T | (() => T)
  • The initial value of the state or a function that returns the initial value.
optional
options: UseLocalStorageOptions<T>
  • Options for customizing the behavior of serialization and deserialization (optional).

Returns

[T, Dispatch<SetStateAction<T>>]

A tuple containing the stored value and a function to set the value.