UNPKG

@thibault.sh/hooks

Version:

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

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