UNPKG

@thibault.sh/hooks

Version:

A comprehensive collection of React hooks for browser storage, UI interactions, and more

2 lines 637 B
import {useState,useEffect}from'react';function u(t,r){let n=()=>{if(typeof window=="undefined")return r;try{let e=window.localStorage.getItem(t);return e?JSON.parse(e):r}catch(e){return console.warn(`Error reading localStorage key "${t}":`,e),r}},[a,c]=useState(n),s=e=>{try{let o=e instanceof Function?e(a):e;c(o),typeof window!="undefined"&&window.localStorage.setItem(t,JSON.stringify(o));}catch(o){console.warn(`Error setting localStorage key "${t}":`,o);}};return useEffect(()=>{c(n());},[]),[a,s]}export{u as useLocalStorageState};//# sourceMappingURL=useLocalStorageState.mjs.map //# sourceMappingURL=useLocalStorageState.mjs.map