New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-hookstack

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hookstack - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+27
-0
dist/index.d.ts
export * from './hooks/useToggle';
export * from './hooks/useArray';
export * from './hooks/useLocalStorage';
export * from './hooks/useDebounce';
export * from './hooks/usePrevious';
export * from './hooks/useClickOutside';
export * from './hooks/useEventListener';
export * from './hooks/useDarkMode';
export * from './hooks/useCopyToClipboard';
export * from './hooks/useMediaQuery';
export * from './hooks/useHover';
export * from './hooks/useWindowSize';
export * from './hooks/useAsync';
export * from './hooks/useBoolean';
export * from './hooks/useCounter';
export * from './hooks/useDeviceOrientation';
export * from './hooks/useFocus';
export * from './hooks/useFormState';
export * from './hooks/useInput';
export * from './hooks/useInterval';
export * from './hooks/useLocalStorage';
export * from './hooks/useMap';
export * from './hooks/useOnlineStatus';
export * from './hooks/useRafState';
export * from './hooks/useSessionStorage';
export * from './hooks/useThrottle';
export * from './hooks/useTimeout';
export * from './hooks/useUpdateEffect';
+464
-7

@@ -1,12 +0,469 @@

import { useState as u, useCallback as n } from "react";
function c(o = !1) {
const [t, l] = u(o), s = n((e) => {
l(
(a) => typeof e == "boolean" ? e : !a
import { useState as d, useCallback as i, useEffect as m, useRef as g } from "react";
function O(e = !1) {
const [t, n] = d(e), r = i((o) => {
n(
(s) => typeof o == "boolean" ? o : !s
);
}, []);
return [t, s];
return [t, r];
}
function C(e = []) {
const [t, n] = d(e), r = i((f) => {
n((w) => [...w, f]);
}, []), o = i((f) => {
n((w) => w.filter((h, S) => S !== f));
}, []), s = i((f, w) => {
n(
(h) => h.map((S, p) => p === f ? w : S)
);
}, []), u = i((f, w) => {
n((h) => [
...h.slice(0, f),
w,
...h.slice(f)
]);
}, []), c = i((f) => {
n(f);
}, []), l = i(() => {
n([]);
}, []), a = t.length === 0;
return {
array: t,
set: c,
push: r,
remove: o,
update: s,
insert: u,
clear: l,
isEmpty: a
};
}
function T(e, t) {
const n = () => {
if (typeof window > "u") return t;
try {
const c = window.localStorage.getItem(e);
return c ? JSON.parse(c) : t;
} catch (c) {
return console.warn(
`[react-handyhooks]: Error reading localStorage key “${e}”:`,
c
), t;
}
}, [r, o] = d(n), s = (c) => {
try {
const l = c instanceof Function ? c(r) : c;
o(l), typeof window < "u" && window.localStorage.setItem(e, JSON.stringify(l));
} catch (l) {
console.warn(
`[react-handyhooks]: Error setting localStorage key “${e}”:`,
l
);
}
}, u = () => {
try {
o(t), typeof window < "u" && window.localStorage.removeItem(e);
} catch (c) {
console.warn(
`[react-handyhooks]: Error removing localStorage key “${e}”:`,
c
);
}
};
return m(() => {
const c = (l) => {
l.key === e && o(
l.newValue ? JSON.parse(l.newValue) : t
);
};
return window.addEventListener("storage", c), () => window.removeEventListener("storage", c);
}, [e]), [r, s, u];
}
function k(e, t = 500) {
const [n, r] = d(e);
return m(() => {
const o = setTimeout(() => {
r(e);
}, t);
return () => {
clearTimeout(o);
};
}, [e, t]), n;
}
function D(e) {
const t = g(void 0);
return m(() => {
t.current = e;
}, [e]), t.current;
}
function V(e, t, n = "mousedown") {
m(() => {
const r = (o) => {
const s = e?.current;
!s || s.contains(o.target) || t(o);
};
return document.addEventListener(n, r, !0), () => {
document.removeEventListener(n, r, !0);
};
}, [e, t, n]);
}
function F(e, t, n) {
const r = g(null);
m(() => {
r.current = t;
}, [t]), m(() => {
const o = n ?? window;
if (!(o && o.addEventListener)) return;
const s = (u) => {
r.current && r.current(u);
};
return o.addEventListener(e, s), () => {
o.removeEventListener(e, s);
};
}, [e, n]);
}
function x(e = "theme", t = !1) {
const n = () => typeof window > "u" || !window.matchMedia ? t : window.matchMedia("(prefers-color-scheme: dark)").matches, r = () => {
if (typeof window > "u") return t;
const a = localStorage.getItem(e);
return a !== null ? a === "dark" : n();
}, [o, s] = d(r);
m(() => {
const a = window.document.documentElement;
o ? (a.classList.add("dark"), localStorage.setItem(e, "dark")) : (a.classList.remove("dark"), localStorage.setItem(e, "light"));
}, [o, e]), m(() => {
const a = window.matchMedia("(prefers-color-scheme: dark)"), f = (w) => s(w.matches);
return a.addEventListener("change", f), () => a.removeEventListener("change", f);
}, []);
const u = i(() => s(!0), []), c = i(() => s(!1), []), l = i(() => s((a) => !a), []);
return { isDarkMode: o, enable: u, disable: c, toggle: l };
}
function H() {
const [e, t] = d(null), [n, r] = d(!1), o = i(async (u) => {
if (!u)
return r(!1), !1;
try {
if (navigator.clipboard && navigator.clipboard.writeText)
await navigator.clipboard.writeText(u);
else {
const c = document.createElement("textarea");
c.value = u, c.style.position = "fixed", c.style.opacity = "0", document.body.appendChild(c), c.focus(), c.select(), document.execCommand("copy"), document.body.removeChild(c);
}
return t(u), r(!0), !0;
} catch (c) {
return console.error("Failed to copy:", c), r(!1), !1;
}
}, []), s = i(() => {
t(null), r(!1);
}, []);
return { value: e, success: n, copy: o, reset: s };
}
function z(e) {
const [t, n] = d(() => typeof window < "u" ? window.matchMedia(e).matches : !1);
return m(() => {
if (typeof window > "u") return;
const r = window.matchMedia(e), o = (s) => n(s.matches);
return n(r.matches), r.addEventListener("change", o), () => {
r.removeEventListener("change", o);
};
}, [e]), t;
}
function J() {
const e = g(null), [t, n] = d(!1);
return m(() => {
const r = e.current;
if (!r) return;
const o = () => n(!0), s = () => n(!1);
return r.addEventListener("mouseenter", o), r.addEventListener("mouseleave", s), () => {
r.removeEventListener("mouseenter", o), r.removeEventListener("mouseleave", s);
};
}, []), { ref: e, isHovered: t };
}
function $() {
const [e, t] = d({
width: typeof window < "u" ? window.innerWidth : 0,
height: typeof window < "u" ? window.innerHeight : 0
});
return m(() => {
if (typeof window > "u") return;
const n = () => {
t({
width: window.innerWidth,
height: window.innerHeight
});
};
return window.addEventListener("resize", n), n(), () => window.removeEventListener("resize", n);
}, []), e;
}
function A(e, t = !1) {
const [n, r] = d(null), [o, s] = d(null), [u, c] = d(!1), l = g(!0), a = i(
async (...w) => {
c(!0), s(null);
try {
const h = await e(...w);
return l.current && r(h), h;
} catch (h) {
l.current && s(h);
} finally {
l.current && c(!1);
}
},
[e]
), f = i(() => {
r(null), s(null);
}, []);
return m(() => () => {
l.current = !1;
}, []), m(() => {
t && a();
}, [t, a]), { execute: a, data: n, error: o, isLoading: u, reset: f };
}
function N(e = !1) {
const [t, n] = d(e), r = i(() => n(!0), []), o = i(() => n(!1), []), s = i(() => n((u) => !u), []);
return { value: t, setTrue: r, setFalse: o, toggle: s, setValue: n };
}
function R(e = 0, t = {}) {
const { min: n, max: r, step: o = 1 } = t, [s, u] = d(e), c = i(() => {
u((w) => {
const h = w + o;
return r !== void 0 && h > r ? r : h;
});
}, [r, o]), l = i(() => {
u((w) => {
const h = w - o;
return n !== void 0 && h < n ? n : h;
});
}, [n, o]), a = i(() => u(e), [e]), f = i((w) => u(w), []);
return { count: s, increment: c, decrement: l, reset: a, set: f };
}
function W() {
const [e, t] = d({
alpha: null,
beta: null,
gamma: null,
absolute: null
});
return m(() => {
const n = (r) => {
t({
alpha: r.alpha ?? null,
beta: r.beta ?? null,
gamma: r.gamma ?? null,
absolute: r.absolute ?? null
});
};
return window.DeviceOrientationEvent ? window.addEventListener("deviceorientation", n) : console.warn(
"DeviceOrientationEvent is not supported by this browser."
), () => {
window.removeEventListener("deviceorientation", n);
};
}, []), e;
}
function Q() {
const e = g(null), t = g(!1), n = i(() => {
e.current && (e.current.focus(), t.current = !0);
}, []), r = i(() => {
e.current && (e.current.blur(), t.current = !1);
}, []);
return { ref: e, focus: n, blur: r, isFocused: t.current };
}
function B(e, t) {
const [n, r] = d(e), [o, s] = d({}), [u, c] = d(
{}
), [l, a] = d(!1), f = i(
(p) => {
const v = p.target, { name: E, value: L, type: b } = v, y = v instanceof HTMLInputElement && b === "checkbox" ? v.checked : L;
r((M) => ({ ...M, [E]: y })), t && s(t({ ...n, [E]: y }));
},
[t, n]
), w = i(
(p) => {
const { name: v } = p.target;
c((E) => ({ ...E, [v]: !0 })), t && s(t(n));
},
[t, n]
), h = i(
(p) => async (v) => {
if (v.preventDefault(), a(!0), t) {
const E = t(n);
if (s(E), Object.keys(E).length > 0) {
a(!1);
return;
}
}
await p(n), a(!1);
},
[t, n]
), S = i(() => {
r(e), s({}), c({}), a(!1);
}, [e]);
return {
values: n,
errors: o,
touched: u,
isSubmitting: l,
handleChange: f,
handleBlur: w,
handleSubmit: h,
resetForm: S
};
}
function P(e = "", t) {
const [n, r] = d(e), [o, s] = d(), u = i(
(l) => {
const a = l.target.value;
if (r(a), t) {
const f = t(a);
s(f);
}
},
[t]
), c = i(() => {
r(e), s(void 0);
}, [e]);
return { value: n, error: o, onChange: u, reset: c, setValue: r };
}
function j(e, t) {
const n = g(null);
m(() => {
n.current = e;
}, [e]), m(() => {
if (t === null) return;
const o = setInterval(() => n.current && n.current(), t);
return () => clearInterval(o);
}, [t]);
}
function U(e) {
const [t, n] = d(() => new Map(e)), r = i((a, f) => {
n((w) => {
const h = new Map(w);
return h.set(a, f), h;
});
}, []), o = i((a) => {
n((f) => {
const w = new Map(f);
return w.delete(a), w;
});
}, []), s = i((a) => t.get(a), [t]), u = i((a) => t.has(a), [t]), c = i(() => {
n(/* @__PURE__ */ new Map());
}, []), l = i(() => {
n(new Map(e));
}, [e]);
return { map: t, set: r, get: s, remove: o, has: u, clear: c, reset: l };
}
function _() {
const [e, t] = d(
typeof navigator < "u" ? navigator.onLine : !0
);
return m(() => {
const n = () => t(!0), r = () => t(!1);
return window.addEventListener("online", n), window.addEventListener("offline", r), t(navigator.onLine), () => {
window.removeEventListener("online", n), window.removeEventListener("offline", r);
};
}, []), e;
}
function G(e) {
const [t, n] = d(e), r = g(t), o = i((s) => {
n((u) => {
const c = typeof s == "function" ? s(u) : s;
return r.current = c, c;
});
}, []);
return r.current = t, [t, o, r];
}
function X(e, t) {
const n = () => {
if (typeof window > "u") return t;
try {
const u = window.sessionStorage.getItem(e);
return u ? JSON.parse(u) : t;
} catch (u) {
return console.warn(`Error reading sessionStorage key “${e}”:`, u), t;
}
}, [r, o] = d(n), s = (u) => {
try {
const c = u instanceof Function ? u(r) : u;
o(c), typeof window < "u" && window.sessionStorage.setItem(
e,
JSON.stringify(c)
);
} catch (c) {
console.warn(`Error setting sessionStorage key “${e}”:`, c);
}
};
return m(() => {
const u = (c) => {
c.storageArea === window.sessionStorage && c.key === e && o(
c.newValue ? JSON.parse(c.newValue) : t
);
};
return window.addEventListener("storage", u), () => window.removeEventListener("storage", u);
}, [e, t]), [r, s];
}
function Y(e, t = 300) {
const [n, r] = d(e), o = g(Date.now());
return m(() => {
const s = Date.now(), u = t - (s - o.current);
if (u <= 0)
r(e), o.current = s;
else {
const c = setTimeout(() => {
r(e), o.current = Date.now();
}, u);
return () => clearTimeout(c);
}
}, [e, t]), n;
}
function Z(e, t) {
const n = g(e), r = g(null);
m(() => {
n.current = e;
}, [e]);
const o = i(() => {
r.current && (clearTimeout(r.current), r.current = null);
}, []), s = i(() => {
t !== null && (o(), r.current = setTimeout(() => {
n.current();
}, t));
}, [t, o]);
return m(() => (s(), o), [s, o]), { clear: o, reset: s };
}
function q(e, t) {
const n = g(!0);
m(() => {
if (n.current) {
n.current = !1;
return;
}
return e();
}, t);
}
export {
c as useToggle
C as useArray,
A as useAsync,
N as useBoolean,
V as useClickOutside,
H as useCopyToClipboard,
R as useCounter,
x as useDarkMode,
k as useDebounce,
W as useDeviceOrientation,
F as useEventListener,
Q as useFocus,
B as useFormState,
J as useHover,
P as useInput,
j as useInterval,
T as useLocalStorage,
U as useMap,
z as useMediaQuery,
_ as useOnlineStatus,
D as usePrevious,
G as useRefState,
X as useSessionStorage,
Y as useThrottle,
Z as useTimeout,
O as useToggle,
q as useUpdateEffect,
$ as useWindowSize
};
+1
-1

@@ -1,1 +0,1 @@

(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.ReactHandyhooks={},e.React))})(this,(function(e,t){"use strict";function n(s=!1){const[u,i]=t.useState(s),f=t.useCallback(o=>{i(d=>typeof o=="boolean"?o:!d)},[]);return[u,f]}e.useToggle=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
(function(l,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(l=typeof globalThis<"u"?globalThis:l||self,e(l.ReactHandyhooks={},l.React))})(this,(function(l,e){"use strict";function C(n=!1){const[t,s]=e.useState(n),o=e.useCallback(u=>{s(r=>typeof u=="boolean"?u:!r)},[]);return[t,o]}function k(n=[]){const[t,s]=e.useState(n),o=e.useCallback(d=>{s(w=>[...w,d])},[]),u=e.useCallback(d=>{s(w=>w.filter((m,E)=>E!==d))},[]),r=e.useCallback((d,w)=>{s(m=>m.map((E,h)=>h===d?w:E))},[]),i=e.useCallback((d,w)=>{s(m=>[...m.slice(0,d),w,...m.slice(d)])},[]),c=e.useCallback(d=>{s(d)},[]),f=e.useCallback(()=>{s([])},[]),a=t.length===0;return{array:t,set:c,push:o,remove:u,update:r,insert:i,clear:f,isEmpty:a}}function y(n,t){const s=()=>{if(typeof window>"u")return t;try{const c=window.localStorage.getItem(n);return c?JSON.parse(c):t}catch(c){return console.warn(`[react-handyhooks]: Error reading localStorage key “${n}”:`,c),t}},[o,u]=e.useState(s),r=c=>{try{const f=c instanceof Function?c(o):c;u(f),typeof window<"u"&&window.localStorage.setItem(n,JSON.stringify(f))}catch(f){console.warn(`[react-handyhooks]: Error setting localStorage key “${n}”:`,f)}},i=()=>{try{u(t),typeof window<"u"&&window.localStorage.removeItem(n)}catch(c){console.warn(`[react-handyhooks]: Error removing localStorage key “${n}”:`,c)}};return e.useEffect(()=>{const c=f=>{f.key===n&&u(f.newValue?JSON.parse(f.newValue):t)};return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[n]),[o,r,i]}function p(n,t=500){const[s,o]=e.useState(n);return e.useEffect(()=>{const u=setTimeout(()=>{o(n)},t);return()=>{clearTimeout(u)}},[n,t]),s}function L(n){const t=e.useRef(void 0);return e.useEffect(()=>{t.current=n},[n]),t.current}function M(n,t,s="mousedown"){e.useEffect(()=>{const o=u=>{const r=n?.current;!r||r.contains(u.target)||t(u)};return document.addEventListener(s,o,!0),()=>{document.removeEventListener(s,o,!0)}},[n,t,s])}function I(n,t,s){const o=e.useRef(null);e.useEffect(()=>{o.current=t},[t]),e.useEffect(()=>{const u=s??window;if(!(u&&u.addEventListener))return;const r=i=>{o.current&&o.current(i)};return u.addEventListener(n,r),()=>{u.removeEventListener(n,r)}},[n,s])}function O(n="theme",t=!1){const s=()=>typeof window>"u"||!window.matchMedia?t:window.matchMedia("(prefers-color-scheme: dark)").matches,o=()=>{if(typeof window>"u")return t;const a=localStorage.getItem(n);return a!==null?a==="dark":s()},[u,r]=e.useState(o);e.useEffect(()=>{const a=window.document.documentElement;u?(a.classList.add("dark"),localStorage.setItem(n,"dark")):(a.classList.remove("dark"),localStorage.setItem(n,"light"))},[u,n]),e.useEffect(()=>{const a=window.matchMedia("(prefers-color-scheme: dark)"),d=w=>r(w.matches);return a.addEventListener("change",d),()=>a.removeEventListener("change",d)},[]);const i=e.useCallback(()=>r(!0),[]),c=e.useCallback(()=>r(!1),[]),f=e.useCallback(()=>r(a=>!a),[]);return{isDarkMode:u,enable:i,disable:c,toggle:f}}function T(){const[n,t]=e.useState(null),[s,o]=e.useState(!1),u=e.useCallback(async i=>{if(!i)return o(!1),!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(i);else{const c=document.createElement("textarea");c.value=i,c.style.position="fixed",c.style.opacity="0",document.body.appendChild(c),c.focus(),c.select(),document.execCommand("copy"),document.body.removeChild(c)}return t(i),o(!0),!0}catch(c){return console.error("Failed to copy:",c),o(!1),!1}},[]),r=e.useCallback(()=>{t(null),o(!1)},[]);return{value:n,success:s,copy:u,reset:r}}function R(n){const[t,s]=e.useState(()=>typeof window<"u"?window.matchMedia(n).matches:!1);return e.useEffect(()=>{if(typeof window>"u")return;const o=window.matchMedia(n),u=r=>s(r.matches);return s(o.matches),o.addEventListener("change",u),()=>{o.removeEventListener("change",u)}},[n]),t}function D(){const n=e.useRef(null),[t,s]=e.useState(!1);return e.useEffect(()=>{const o=n.current;if(!o)return;const u=()=>s(!0),r=()=>s(!1);return o.addEventListener("mouseenter",u),o.addEventListener("mouseleave",r),()=>{o.removeEventListener("mouseenter",u),o.removeEventListener("mouseleave",r)}},[]),{ref:n,isHovered:t}}function V(){const[n,t]=e.useState({width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0});return e.useEffect(()=>{if(typeof window>"u")return;const s=()=>{t({width:window.innerWidth,height:window.innerHeight})};return window.addEventListener("resize",s),s(),()=>window.removeEventListener("resize",s)},[]),n}function F(n,t=!1){const[s,o]=e.useState(null),[u,r]=e.useState(null),[i,c]=e.useState(!1),f=e.useRef(!0),a=e.useCallback(async(...w)=>{c(!0),r(null);try{const m=await n(...w);return f.current&&o(m),m}catch(m){f.current&&r(m)}finally{f.current&&c(!1)}},[n]),d=e.useCallback(()=>{o(null),r(null)},[]);return e.useEffect(()=>()=>{f.current=!1},[]),e.useEffect(()=>{t&&a()},[t,a]),{execute:a,data:s,error:u,isLoading:i,reset:d}}function H(n=!1){const[t,s]=e.useState(n),o=e.useCallback(()=>s(!0),[]),u=e.useCallback(()=>s(!1),[]),r=e.useCallback(()=>s(i=>!i),[]);return{value:t,setTrue:o,setFalse:u,toggle:r,setValue:s}}function z(n=0,t={}){const{min:s,max:o,step:u=1}=t,[r,i]=e.useState(n),c=e.useCallback(()=>{i(w=>{const m=w+u;return o!==void 0&&m>o?o:m})},[o,u]),f=e.useCallback(()=>{i(w=>{const m=w-u;return s!==void 0&&m<s?s:m})},[s,u]),a=e.useCallback(()=>i(n),[n]),d=e.useCallback(w=>i(w),[]);return{count:r,increment:c,decrement:f,reset:a,set:d}}function A(){const[n,t]=e.useState({alpha:null,beta:null,gamma:null,absolute:null});return e.useEffect(()=>{const s=o=>{t({alpha:o.alpha??null,beta:o.beta??null,gamma:o.gamma??null,absolute:o.absolute??null})};return window.DeviceOrientationEvent?window.addEventListener("deviceorientation",s):console.warn("DeviceOrientationEvent is not supported by this browser."),()=>{window.removeEventListener("deviceorientation",s)}},[]),n}function J(){const n=e.useRef(null),t=e.useRef(!1),s=e.useCallback(()=>{n.current&&(n.current.focus(),t.current=!0)},[]),o=e.useCallback(()=>{n.current&&(n.current.blur(),t.current=!1)},[]);return{ref:n,focus:s,blur:o,isFocused:t.current}}function W(n,t){const[s,o]=e.useState(n),[u,r]=e.useState({}),[i,c]=e.useState({}),[f,a]=e.useState(!1),d=e.useCallback(h=>{const g=h.target,{name:S,value:b,type:X}=g,v=g instanceof HTMLInputElement&&X==="checkbox"?g.checked:b;o(Y=>({...Y,[S]:v})),t&&r(t({...s,[S]:v}))},[t,s]),w=e.useCallback(h=>{const{name:g}=h.target;c(S=>({...S,[g]:!0})),t&&r(t(s))},[t,s]),m=e.useCallback(h=>async g=>{if(g.preventDefault(),a(!0),t){const S=t(s);if(r(S),Object.keys(S).length>0){a(!1);return}}await h(s),a(!1)},[t,s]),E=e.useCallback(()=>{o(n),r({}),c({}),a(!1)},[n]);return{values:s,errors:u,touched:i,isSubmitting:f,handleChange:d,handleBlur:w,handleSubmit:m,resetForm:E}}function $(n="",t){const[s,o]=e.useState(n),[u,r]=e.useState(),i=e.useCallback(f=>{const a=f.target.value;if(o(a),t){const d=t(a);r(d)}},[t]),c=e.useCallback(()=>{o(n),r(void 0)},[n]);return{value:s,error:u,onChange:i,reset:c,setValue:o}}function N(n,t){const s=e.useRef(null);e.useEffect(()=>{s.current=n},[n]),e.useEffect(()=>{if(t===null)return;const u=setInterval(()=>s.current&&s.current(),t);return()=>clearInterval(u)},[t])}function P(n){const[t,s]=e.useState(()=>new Map(n)),o=e.useCallback((a,d)=>{s(w=>{const m=new Map(w);return m.set(a,d),m})},[]),u=e.useCallback(a=>{s(d=>{const w=new Map(d);return w.delete(a),w})},[]),r=e.useCallback(a=>t.get(a),[t]),i=e.useCallback(a=>t.has(a),[t]),c=e.useCallback(()=>{s(new Map)},[]),f=e.useCallback(()=>{s(new Map(n))},[n]);return{map:t,set:o,get:r,remove:u,has:i,clear:c,reset:f}}function Q(){const[n,t]=e.useState(typeof navigator<"u"?navigator.onLine:!0);return e.useEffect(()=>{const s=()=>t(!0),o=()=>t(!1);return window.addEventListener("online",s),window.addEventListener("offline",o),t(navigator.onLine),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",o)}},[]),n}function j(n){const[t,s]=e.useState(n),o=e.useRef(t),u=e.useCallback(r=>{s(i=>{const c=typeof r=="function"?r(i):r;return o.current=c,c})},[]);return o.current=t,[t,u,o]}function B(n,t){const s=()=>{if(typeof window>"u")return t;try{const i=window.sessionStorage.getItem(n);return i?JSON.parse(i):t}catch(i){return console.warn(`Error reading sessionStorage key “${n}”:`,i),t}},[o,u]=e.useState(s),r=i=>{try{const c=i instanceof Function?i(o):i;u(c),typeof window<"u"&&window.sessionStorage.setItem(n,JSON.stringify(c))}catch(c){console.warn(`Error setting sessionStorage key “${n}”:`,c)}};return e.useEffect(()=>{const i=c=>{c.storageArea===window.sessionStorage&&c.key===n&&u(c.newValue?JSON.parse(c.newValue):t)};return window.addEventListener("storage",i),()=>window.removeEventListener("storage",i)},[n,t]),[o,r]}function U(n,t=300){const[s,o]=e.useState(n),u=e.useRef(Date.now());return e.useEffect(()=>{const r=Date.now(),i=t-(r-u.current);if(i<=0)o(n),u.current=r;else{const c=setTimeout(()=>{o(n),u.current=Date.now()},i);return()=>clearTimeout(c)}},[n,t]),s}function _(n,t){const s=e.useRef(n),o=e.useRef(null);e.useEffect(()=>{s.current=n},[n]);const u=e.useCallback(()=>{o.current&&(clearTimeout(o.current),o.current=null)},[]),r=e.useCallback(()=>{t!==null&&(u(),o.current=setTimeout(()=>{s.current()},t))},[t,u]);return e.useEffect(()=>(r(),u),[r,u]),{clear:u,reset:r}}function G(n,t){const s=e.useRef(!0);e.useEffect(()=>{if(s.current){s.current=!1;return}return n()},t)}l.useArray=k,l.useAsync=F,l.useBoolean=H,l.useClickOutside=M,l.useCopyToClipboard=T,l.useCounter=z,l.useDarkMode=O,l.useDebounce=p,l.useDeviceOrientation=A,l.useEventListener=I,l.useFocus=J,l.useFormState=W,l.useHover=D,l.useInput=$,l.useInterval=N,l.useLocalStorage=y,l.useMap=P,l.useMediaQuery=R,l.useOnlineStatus=Q,l.usePrevious=L,l.useRefState=j,l.useSessionStorage=B,l.useThrottle=U,l.useTimeout=_,l.useToggle=C,l.useUpdateEffect=G,l.useWindowSize=V,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
{
"name": "react-hookstack",
"version": "1.0.1",
"version": "1.0.2",
"description": "A collection of powerful and reusable React hooks.",

@@ -5,0 +5,0 @@ "main": "dist/react-handyhooks.umd.js",