Skip to content

Instantly share code, notes, and snippets.

@Mon4ik
Mon4ik / useLocalStorage.ts
Last active May 26, 2024 06:23
Typescript useLocalStorage hook
/* `useLocalStorage`
*
* Features:
* - JSON Serializing
* - Also value will be updated everywhere, when value updated (via `storage` event)
*/
import { useEffect, useState } from "react";
export default function useLocalStorage<T>(key: string, defaultValue: T): [T, (value: T) => void] {