UNPKG

@thibault.sh/hooks

Version:

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

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