foxact 0.2.6 → 0.2.8-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/context-state/index.d.ts +1 -0
- package/create-context-state/index.d.ts +3 -1
- package/noop/index.d.ts +1 -0
- package/package.json +20 -11
- package/request-idle-callback/index.d.ts +2 -0
- package/sizes.json +1 -1
- package/typescript-happy-forward-ref/index.cjs +1 -1
- package/typescript-happy-forward-ref/index.d.ts +4 -1
- package/typescript-happy-forward-ref/index.js +1 -1
- package/typescript-happy-forward-ref/index.mjs +1 -1
- package/use-clipboard/index.cjs +1 -1
- package/use-clipboard/index.d.ts +3 -1
- package/use-clipboard/index.js +1 -1
- package/use-clipboard/index.mjs +1 -1
- package/use-error-boundary/index.d.ts +1 -0
- package/use-intersection/index.d.ts +1 -0
- package/use-isomorphic-layout-effect/index.d.ts +5 -3
- package/use-map/index.cjs +1 -1
- package/use-map/index.d.ts +1 -1
- package/use-map/index.js +1 -1
- package/use-map/index.mjs +1 -1
- package/use-retimer/index.d.ts +1 -0
- package/use-set/index.cjs +1 -1
- package/use-set/index.d.ts +1 -1
- package/use-set/index.js +1 -1
- package/use-set/index.mjs +1 -1
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs +1 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts +9 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js +1 -0
- package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs +1 -0
- package/use-uncontrolled/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ React Hooks/Utils done right. For Browser, SSR, and React Server Components.
|
|
|
6
6
|
|
|
7
7
|
## Documentation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
https://foxact.skk.moe
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ The entire **foxact** library has zero dependencies and is **less than 5 KiB gzi
|
|
|
34
34
|
|
|
35
35
|
#### Fully Tree Shakable
|
|
36
36
|
|
|
37
|
-
Feel free to take what you want from **foxact** without worrying about client bundle size.
|
|
37
|
+
Every hook and util is isolated and side-effects free. Feel free to take what you want from **foxact** without worrying about client bundle size.
|
|
38
38
|
|
|
39
39
|
## License
|
|
40
40
|
|
package/context-state/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
|
+
/** @see https://foxact.skk.moe/context-state */
|
|
4
5
|
declare function createContextState<T>(initialState: T): readonly [({ children }: React.PropsWithChildren) => react_jsx_runtime.JSX.Element, () => T, () => react.Dispatch<react.SetStateAction<T>>];
|
|
5
6
|
|
|
6
7
|
export { createContextState };
|
package/noop/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxact",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8-alpha.0",
|
|
4
4
|
"description": "React Hooks/Utils done right. For browser, SSR, and React Server Components.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/SukkaW/foxact/issues"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://foxact.skk.moe",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"client-only": "^0.0.1",
|
|
25
25
|
"server-only": "^0.0.1"
|
|
@@ -47,15 +47,6 @@
|
|
|
47
47
|
"exports": {
|
|
48
48
|
"./package.json": "./package.json",
|
|
49
49
|
"./sizes.json": "./sizes.json",
|
|
50
|
-
"./create-context-state": {
|
|
51
|
-
"types": "./create-context-state/index.d.ts",
|
|
52
|
-
"import": {
|
|
53
|
-
"types": "./create-context-state/index.d.ts",
|
|
54
|
-
"default": "./create-context-state/index.mjs"
|
|
55
|
-
},
|
|
56
|
-
"require": "./create-context-state/index.cjs",
|
|
57
|
-
"default": "./create-context-state/index.js"
|
|
58
|
-
},
|
|
59
50
|
"./context-state": {
|
|
60
51
|
"types": "./context-state/index.d.ts",
|
|
61
52
|
"import": {
|
|
@@ -65,6 +56,15 @@
|
|
|
65
56
|
"require": "./context-state/index.cjs",
|
|
66
57
|
"default": "./context-state/index.js"
|
|
67
58
|
},
|
|
59
|
+
"./create-context-state": {
|
|
60
|
+
"types": "./create-context-state/index.d.ts",
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./create-context-state/index.d.ts",
|
|
63
|
+
"default": "./create-context-state/index.mjs"
|
|
64
|
+
},
|
|
65
|
+
"require": "./create-context-state/index.cjs",
|
|
66
|
+
"default": "./create-context-state/index.js"
|
|
67
|
+
},
|
|
68
68
|
"./noop": {
|
|
69
69
|
"types": "./noop/index.d.ts",
|
|
70
70
|
"import": {
|
|
@@ -164,6 +164,15 @@
|
|
|
164
164
|
"require": "./use-set/index.cjs",
|
|
165
165
|
"default": "./use-set/index.js"
|
|
166
166
|
},
|
|
167
|
+
"./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired": {
|
|
168
|
+
"types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
|
|
169
|
+
"import": {
|
|
170
|
+
"types": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts",
|
|
171
|
+
"default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs"
|
|
172
|
+
},
|
|
173
|
+
"require": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs",
|
|
174
|
+
"default": "./use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js"
|
|
175
|
+
},
|
|
167
176
|
"./use-uncontrolled": {
|
|
168
177
|
"types": "./use-uncontrolled/index.d.ts",
|
|
169
178
|
"import": {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/** @see https://foxact.skk.moe/request-idle-callback */
|
|
1
2
|
declare const requestIdleCallback: ((callback: IdleRequestCallback, options?: IdleRequestOptions | undefined) => number) & typeof globalThis.requestIdleCallback;
|
|
3
|
+
/** @see https://foxact.skk.moe/request-idle-callback */
|
|
2
4
|
declare const cancelIdleCallback: ((handle: number) => void) & typeof globalThis.cancelIdleCallback;
|
|
3
5
|
|
|
4
6
|
export { cancelIdleCallback, requestIdleCallback };
|
package/sizes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"total":{"raw":
|
|
1
|
+
{"total":{"raw":5781,"gzip":3804},"exports":{"context-state":{"raw":369,"gzip":240},"create-context-state":{"raw":146,"gzip":119},"noop":{"raw":32,"gzip":52},"request-idle-callback":{"raw":407,"gzip":229},"typescript-happy-forward-ref":{"raw":118,"gzip":102},"use-array":{"raw":329,"gzip":241},"use-clipboard":{"raw":1071,"gzip":617},"use-error-boundary":{"raw":172,"gzip":157},"use-intersection":{"raw":1214,"gzip":649},"use-isomorphic-layout-effect":{"raw":177,"gzip":143},"use-map":{"raw":348,"gzip":246},"use-retimer":{"raw":197,"gzip":165},"use-set":{"raw":349,"gzip":242},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":461,"gzip":327},"use-uncontrolled":{"raw":391,"gzip":275}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=require("react");const e=r.forwardRef;exports.typeScriptHappyForwardRef=e;
|
|
1
|
+
"use strict";var r=require("react");const e=r.forwardRef,p=r.forwardRef;exports.typeScriptHappyForwardRef=e,exports.typescriptHappyForwardRef=p;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
interface TypeScriptHappyForwardRef {
|
|
2
2
|
<T, P = {}>(render: (props: P, ref: React.ForwardedRef<T>) => React.ReactElement | null): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
|
|
3
3
|
}
|
|
4
|
+
/** @see https://foxact.skk.moe/typescript-happy-forward-ref */
|
|
4
5
|
declare const typeScriptHappyForwardRef: TypeScriptHappyForwardRef;
|
|
6
|
+
/** @see https://foxact.skk.moe/typescript-happy-forward-ref */
|
|
7
|
+
declare const typescriptHappyForwardRef: TypeScriptHappyForwardRef;
|
|
5
8
|
|
|
6
|
-
export { TypeScriptHappyForwardRef, typeScriptHappyForwardRef };
|
|
9
|
+
export { TypeScriptHappyForwardRef, typeScriptHappyForwardRef, typescriptHappyForwardRef };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=require("react");const e=r.forwardRef;exports.typeScriptHappyForwardRef=e;
|
|
1
|
+
"use strict";var r=require("react");const e=r.forwardRef,p=r.forwardRef;exports.typeScriptHappyForwardRef=e,exports.typescriptHappyForwardRef=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{forwardRef as
|
|
1
|
+
import{forwardRef as p}from"react";let r=p,t=p;export{r as typeScriptHappyForwardRef,t as typescriptHappyForwardRef};
|
package/use-clipboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");class
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),r=require("../noop/index.cjs"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs");class a extends Error{}exports.UseClipboardError=a,exports.useClipboard=function(){let{timeout:l=1e3,usePromptAsFallback:o=!1,promptFallbackText:i="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[u,c]=e.useState(null),[s,d]=e.useState(!1),p=e.useRef(null),b=t.useStableHandler(n||r.noop),w=e.useCallback(e=>{p.current&&clearTimeout(p.current),e&&(p.current=window.setTimeout(()=>d(!1),l)),d(e)},[l]),y=e.useCallback(e=>{c(e),b(e)},[b]),h=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),w(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(r){if(o)try{window.prompt(i,e)}catch(e){y(e)}else y(r)}},[w,i,y,o]),x=e.useCallback(()=>{d(!1),c(null),p.current&&clearTimeout(p.current)},[]);return{copy:h,reset:x,error:u,copied:s}};
|
package/use-clipboard/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ interface UseClipboardOption {
|
|
|
4
4
|
timeout?: number;
|
|
5
5
|
usePromptAsFallback?: boolean;
|
|
6
6
|
promptFallbackText?: string;
|
|
7
|
+
onCopyError?: (error: Error) => void;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** @see https://foxact.skk.moe/use-clipboard */
|
|
10
|
+
declare function useClipboard({ timeout, usePromptAsFallback, promptFallbackText, onCopyError }?: UseClipboardOption): {
|
|
9
11
|
copy: (valueToCopy: string) => Promise<void>;
|
|
10
12
|
reset: () => void;
|
|
11
13
|
error: Error | null;
|
package/use-clipboard/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");class
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),r=require("../noop/index.js"),t=require("../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js");class a extends Error{}exports.UseClipboardError=a,exports.useClipboard=function(){let{timeout:l=1e3,usePromptAsFallback:o=!1,promptFallbackText:i="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[u,c]=e.useState(null),[s,d]=e.useState(!1),p=e.useRef(null),b=t.useStableHandler(n||r.noop),w=e.useCallback(e=>{p.current&&clearTimeout(p.current),e&&(p.current=window.setTimeout(()=>d(!1),l)),d(e)},[l]),y=e.useCallback(e=>{c(e),b(e)},[b]),h=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),w(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(r){if(o)try{window.prompt(i,e)}catch(e){y(e)}else y(r)}},[w,i,y,o]),x=e.useCallback(()=>{d(!1),c(null),p.current&&clearTimeout(p.current)},[]);return{copy:h,reset:x,error:u,copied:s}};
|
package/use-clipboard/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"client-only";import{useState as r,useRef as
|
|
1
|
+
import"client-only";import{useState as r,useRef as o,useCallback as e}from"react";import{noop as t}from"../noop/index.mjs";import{useStableHandler as i}from"../use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs";class a extends Error{}function l(){let{timeout:l=1e3,usePromptAsFallback:n=!1,promptFallbackText:c="Failed to copy to clipboard automatically, please manually copy the text below.",onCopyError:u}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[p,d]=r(null),[s,m]=r(!1),w=o(null),y=i(u||t),b=e(r=>{w.current&&clearTimeout(w.current),r&&(w.current=window.setTimeout(()=>m(!1),l)),m(r)},[l]),f=e(r=>{d(r),y(r)},[y]),h=e(async r=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(r),b(!0);else throw new a("[foxact] useClipboard: navigator.clipboard is not supported")}catch(o){if(n)try{window.prompt(c,r)}catch(r){f(r)}else f(o)}},[b,c,f,n]),x=e(()=>{m(!1),d(null),w.current&&clearTimeout(w.current)},[]);return{copy:h,reset:x,error:p,copied:s}}export{a as UseClipboardError,l as useClipboard};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
|
|
3
3
|
type ErrorLike = Error | undefined | null | boolean;
|
|
4
|
+
/** @see https://foxact.skk.moe/use-error-boundary */
|
|
4
5
|
declare const useErrorBoundary: (givenError: ErrorLike) => react.Dispatch<react.SetStateAction<ErrorLike>>;
|
|
5
6
|
|
|
6
7
|
export { useErrorBoundary };
|
|
@@ -4,6 +4,7 @@ type UseIntersectionArgs = {
|
|
|
4
4
|
} & UseIntersectionObserverInit & {
|
|
5
5
|
rootRef?: React.RefObject<HTMLElement> | null;
|
|
6
6
|
};
|
|
7
|
+
/** @see https://foxact.skk.moe/use-intersection */
|
|
7
8
|
declare function useIntersection<T extends Element>({ rootRef, rootMargin, disabled }: UseIntersectionArgs): [(element: T | null) => void, boolean, () => void];
|
|
8
9
|
|
|
9
10
|
export { useIntersection };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useLayoutEffect as useLayoutEffect$1 } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
declare const
|
|
3
|
+
/** @see https://foxact.skk.moe/use-isomorphic-layout-effect */
|
|
4
|
+
declare const useIsomorphicLayoutEffect: typeof useLayoutEffect$1;
|
|
5
|
+
/** @see https://foxact.skk.moe/use-isomorphic-layout-effect */
|
|
6
|
+
declare const useLayoutEffect: typeof useLayoutEffect$1;
|
|
5
7
|
|
|
6
8
|
export { useIsomorphicLayoutEffect, useLayoutEffect };
|
package/use-map/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");exports.useMap=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[t
|
|
1
|
+
"use strict";require("client-only");var e=require("react");exports.useMap=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[l,t]=e.useState(a),s=e.useCallback((e,a)=>t(l=>(l.set(e,a),new Map(l))),[]),u=e.useCallback(e=>t(a=>a.has(e)?(a.delete(e),new Map(a)):a),[]),n=e.useCallback(()=>t(new Map),[]),r=e.useCallback(e=>t(e),[]);return[l,s,u,n,r]};
|
package/use-map/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const useMap: <K, T>(initialState?: Map<K, T> | (() => Map<K, T>)) => readonly [Map<K, T>, (k: K, v: T) => void, (k: K) => void, () => void];
|
|
1
|
+
declare const useMap: <K, T>(initialState?: Map<K, T> | (() => Map<K, T>)) => readonly [Map<K, T>, (k: K, v: T) => void, (k: K) => void, () => void, (m: Map<K, T>) => void];
|
|
2
2
|
|
|
3
3
|
export { useMap };
|
package/use-map/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");exports.useMap=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[t
|
|
1
|
+
"use strict";require("client-only");var e=require("react");exports.useMap=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[l,t]=e.useState(a),s=e.useCallback((e,a)=>t(l=>(l.set(e,a),new Map(l))),[]),u=e.useCallback(e=>t(a=>a.has(e)?(a.delete(e),new Map(a)):a),[]),n=e.useCallback(()=>t(new Map),[]),r=e.useCallback(e=>t(e),[]);return[l,s,u,n,r]};
|
package/use-map/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"client-only";import{useState as e,useCallback as t}from"react";let n=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[p,a]=e(n),o=t((e,t)=>a(n=>(n.set(e,t),new Map(n))),[]),r=t(e=>a(t=>t.has(e)?(t.delete(e),new Map(t)):t),[]),l=t(()=>a(new Map),[]);return[p,o,r,l]};export{n as useMap};
|
|
1
|
+
import"client-only";import{useState as e,useCallback as t}from"react";let n=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Map,[p,a]=e(n),o=t((e,t)=>a(n=>(n.set(e,t),new Map(n))),[]),r=t(e=>a(t=>t.has(e)?(t.delete(e),new Map(t)):t),[]),l=t(()=>a(new Map),[]),i=t(e=>a(e),[]);return[p,o,r,l,i]};export{n as useMap};
|
package/use-retimer/index.d.ts
CHANGED
package/use-set/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");exports.useSet=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[a,l]=e.useState(t),
|
|
1
|
+
"use strict";require("client-only");var e=require("react");exports.useSet=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[a,l]=e.useState(t),s=e.useCallback(e=>l(t=>t.has(e)?t:new Set([...t,e])),[]),u=e.useCallback(e=>l(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),n=e.useCallback(()=>l(new Set),[]),r=e.useCallback(e=>l(e),[]);return[a,s,u,n,r]};
|
package/use-set/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const useSet: <T>(initialState?: Set<T> | (() => Set<T>)) => readonly [Set<T>, (item: T) => void, (item: T) => void, () => void];
|
|
1
|
+
declare const useSet: <T>(initialState?: Set<T> | (() => Set<T>)) => readonly [Set<T>, (item: T) => void, (item: T) => void, () => void, (s: Set<T>) => void];
|
|
2
2
|
|
|
3
3
|
export { useSet };
|
package/use-set/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("client-only");var e=require("react");exports.useSet=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[a,l]=e.useState(t),
|
|
1
|
+
"use strict";require("client-only");var e=require("react");exports.useSet=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[a,l]=e.useState(t),s=e.useCallback(e=>l(t=>t.has(e)?t:new Set([...t,e])),[]),u=e.useCallback(e=>l(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),n=e.useCallback(()=>l(new Set),[]),r=e.useCallback(e=>l(e),[]);return[a,s,u,n,r]};
|
package/use-set/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"client-only";import{useState as e,useCallback as t}from"react";let n=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[o,r]=e(n),l=t(e=>r(t=>t.has(e)?t:new Set([...t,e])),[]),i=t(e=>r(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),S=t(()=>r(new Set),[]);return[o,l,i,S]};export{n as useSet};
|
|
1
|
+
import"client-only";import{useState as e,useCallback as t}from"react";let n=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>new Set,[o,r]=e(n),l=t(e=>r(t=>t.has(e)?t:new Set([...t,e])),[]),i=t(e=>r(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),S=t(()=>r(new Set),[]),w=t(e=>r(e),[]);return[o,l,i,S,w]};export{n as useSet};
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("react");const t="undefined"!=typeof window?e.useInsertionEffect||e.useLayoutEffect:e.useEffect;function r(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}exports.useStableHandler=function(n){let o=e.useRef(r);return t(()=>{o.current=n},[n]),e.useCallback(function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];let n=o.current;return n(...t)},[])};
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similar to useCallback, with a few subtle differences:
|
|
3
|
+
* - The returned function is a stable reference, and will always be the same between renders
|
|
4
|
+
* - No dependency lists required
|
|
5
|
+
* - Properties or state accessed within the callback will always be "current"
|
|
6
|
+
*/
|
|
7
|
+
declare function useStableHandler<Args extends any[], Result>(callback: (...args: Args) => Result): (...args: Args) => Result;
|
|
8
|
+
|
|
9
|
+
export { useStableHandler };
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("react");const t="undefined"!=typeof window?e.useInsertionEffect||e.useLayoutEffect:e.useEffect;function r(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}exports.useStableHandler=function(n){let o=e.useRef(r);return t(()=>{o.current=n},[n]),e.useCallback(function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];let n=o.current;return n(...t)},[])};
|
package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useLayoutEffect as t,useEffect as n,useRef as r,useCallback as o}from"react";let f="undefined"!=typeof window?e.useInsertionEffect||t:n;function u(e){let t=r(a);return f(()=>{t.current=e},[e]),o(function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];let o=t.current;return o(...n)},[])}function a(){throw Error("foxact: the stablized handler cannot be invoked before the component has mounted.")}export{u as useStableHandler};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
|
|
3
|
+
/** @see https://foxact.skk.moe/use-uncontrolled */
|
|
3
4
|
declare function useUncontrolled<T, E extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement = HTMLInputElement>(initialValue: T, transformValue?: (value: T) => T): readonly [T, () => void, react.RefObject<E>];
|
|
4
5
|
|
|
5
6
|
export { useUncontrolled };
|