import{useState as r,useCallback as e,useEffect as o}from"react";export{s as sparkRuntime}from"./spark-runtime-wNXbhm34.js";function t(t,n){const[s,a]=r(()=>{try{if("undefined"!=typeof window&&window.spark?.kv){const r=window.spark.kv.get(t);if(void 0!==r)return r}const r=localStorage.getItem(t);return r?JSON.parse(r):n}catch(r){return console.error("Error reading from storage:",r),n}}),i=e(r=>{try{a(e=>{const o="function"==typeof r?r(e):r;return localStorage.setItem(t,JSON.stringify(o)),"undefined"!=typeof window&&window.spark?.kv&&window.spark.kv.set(t,o),o})}catch(r){console.error("Error writing to storage:",r)}},[t]),w=e(()=>{try{localStorage.removeItem(t),"undefined"!=typeof window&&window.spark?.kv&&window.spark.kv.delete(t),a(n)}catch(r){console.error("Error deleting from storage:",r)}},[t,n]);return o(()=>{const r=r=>{if(r.key===t&&null!==r.newValue)try{a(JSON.parse(r.newValue))}catch(r){console.error("Error parsing storage event:",r)}};return window.addEventListener("storage",r),()=>window.removeEventListener("storage",r)},[t]),[s,i,w]}export{t as useKV};
//# sourceMappingURL=index.js.map
