UNPKG

@thibault.sh/hooks

Version:

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

2 lines 647 B
'use strict';var react=require('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]=react.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 react.useEffect(()=>{c(n());},[]),[a,s]}exports.useLocalStorageState=u;//# sourceMappingURL=useLocalStorageState.cjs.map //# sourceMappingURL=useLocalStorageState.cjs.map