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.
Files changed (32) hide show
  1. package/README.md +2 -2
  2. package/context-state/index.d.ts +1 -0
  3. package/create-context-state/index.d.ts +3 -1
  4. package/noop/index.d.ts +1 -0
  5. package/package.json +20 -11
  6. package/request-idle-callback/index.d.ts +2 -0
  7. package/sizes.json +1 -1
  8. package/typescript-happy-forward-ref/index.cjs +1 -1
  9. package/typescript-happy-forward-ref/index.d.ts +4 -1
  10. package/typescript-happy-forward-ref/index.js +1 -1
  11. package/typescript-happy-forward-ref/index.mjs +1 -1
  12. package/use-clipboard/index.cjs +1 -1
  13. package/use-clipboard/index.d.ts +3 -1
  14. package/use-clipboard/index.js +1 -1
  15. package/use-clipboard/index.mjs +1 -1
  16. package/use-error-boundary/index.d.ts +1 -0
  17. package/use-intersection/index.d.ts +1 -0
  18. package/use-isomorphic-layout-effect/index.d.ts +5 -3
  19. package/use-map/index.cjs +1 -1
  20. package/use-map/index.d.ts +1 -1
  21. package/use-map/index.js +1 -1
  22. package/use-map/index.mjs +1 -1
  23. package/use-retimer/index.d.ts +1 -0
  24. package/use-set/index.cjs +1 -1
  25. package/use-set/index.d.ts +1 -1
  26. package/use-set/index.js +1 -1
  27. package/use-set/index.mjs +1 -1
  28. package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.cjs +1 -0
  29. package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.d.ts +9 -0
  30. package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.js +1 -0
  31. package/use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired/index.mjs +1 -0
  32. 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
- Under construction.
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
 
@@ -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 };
@@ -1 +1,3 @@
1
- export { createContextState } from '@/context-state';
1
+ export { createContextState } from '../context-state/index.js';
2
+ import 'react';
3
+ import 'react/jsx-runtime';
package/noop/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  interface Noop {
2
2
  (...args: any[]): any;
3
3
  }
4
+ /** @see https://foxact.skk.moe/noop */
4
5
  declare const noop: Noop;
5
6
 
6
7
  export { Noop, noop };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.6",
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://github.com/SukkaW/foxact#readme",
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":5028,"gzip":3341},"exports":{"create-context-state":{"raw":146,"gzip":119},"context-state":{"raw":369,"gzip":240},"noop":{"raw":32,"gzip":52},"request-idle-callback":{"raw":407,"gzip":229},"typescript-happy-forward-ref":{"raw":83,"gzip":91},"use-array":{"raw":329,"gzip":241},"use-clipboard":{"raw":850,"gzip":504},"use-error-boundary":{"raw":172,"gzip":157},"use-intersection":{"raw":1214,"gzip":649},"use-isomorphic-layout-effect":{"raw":177,"gzip":143},"use-map":{"raw":330,"gzip":240},"use-retimer":{"raw":197,"gzip":165},"use-set":{"raw":331,"gzip":236},"use-uncontrolled":{"raw":391,"gzip":275}}}
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 r}from"react";let p=r;export{p as typeScriptHappyForwardRef};
1
+ import{forwardRef as p}from"react";let r=p,t=p;export{r as typeScriptHappyForwardRef,t as typescriptHappyForwardRef};
@@ -1 +1 @@
1
- "use strict";require("client-only");var e=require("react");class t extends Error{}exports.UseClipboardError=t,exports.useClipboard=function(){let{timeout:r=1e3,usePromptAsFallback:a=!1,promptFallbackText:l="Failed to copy to clipboard automatically, please manually copy the text below."}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[o,i]=e.useState(null),[c,u]=e.useState(!1),n=e.useRef(null),s=e.useCallback(e=>{n.current&&clearTimeout(n.current),e&&(n.current=window.setTimeout(()=>u(!1),r)),u(e)},[r]),p=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),s(!0);else throw new t("[foxact] useClipboard: navigator.clipboard is not supported")}catch(t){if(a)try{window.prompt(l,e)}catch(e){i(e)}else i(t)}},[s]),d=e.useCallback(()=>{u(!1),i(null),n.current&&clearTimeout(n.current)},[]);return{copy:p,reset:d,error:o,copied:c}};
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}};
@@ -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
- declare function useClipboard({ timeout, usePromptAsFallback, promptFallbackText }?: UseClipboardOption): {
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;
@@ -1 +1 @@
1
- "use strict";require("client-only");var e=require("react");class t extends Error{}exports.UseClipboardError=t,exports.useClipboard=function(){let{timeout:r=1e3,usePromptAsFallback:a=!1,promptFallbackText:l="Failed to copy to clipboard automatically, please manually copy the text below."}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[o,i]=e.useState(null),[c,u]=e.useState(!1),n=e.useRef(null),s=e.useCallback(e=>{n.current&&clearTimeout(n.current),e&&(n.current=window.setTimeout(()=>u(!1),r)),u(e)},[r]),p=e.useCallback(async e=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(e),s(!0);else throw new t("[foxact] useClipboard: navigator.clipboard is not supported")}catch(t){if(a)try{window.prompt(l,e)}catch(e){i(e)}else i(t)}},[s]),d=e.useCallback(()=>{u(!1),i(null),n.current&&clearTimeout(n.current)},[]);return{copy:p,reset:d,error:o,copied:c}};
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}};
@@ -1 +1 @@
1
- import"client-only";import{useState as r,useRef as t,useCallback as e}from"react";class o extends Error{}function a(){let{timeout:a=1e3,usePromptAsFallback:l=!1,promptFallbackText:i="Failed to copy to clipboard automatically, please manually copy the text below."}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[n,c]=r(null),[u,p]=r(!1),d=t(null),s=e(r=>{d.current&&clearTimeout(d.current),r&&(d.current=window.setTimeout(()=>p(!1),a)),p(r)},[a]),m=e(async r=>{try{if("clipboard"in navigator)await navigator.clipboard.writeText(r),s(!0);else throw new o("[foxact] useClipboard: navigator.clipboard is not supported")}catch(t){if(l)try{window.prompt(i,r)}catch(r){c(r)}else c(t)}},[s]),w=e(()=>{p(!1),c(null),d.current&&clearTimeout(d.current)},[]);return{copy:m,reset:w,error:n,copied:u}}export{o as UseClipboardError,a as useClipboard};
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 { useEffect } from 'react';
1
+ import { useLayoutEffect as useLayoutEffect$1 } from 'react';
2
2
 
3
- declare const useIsomorphicLayoutEffect: typeof useEffect;
4
- declare const useLayoutEffect: typeof useEffect;
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,l]=e.useState(a),n=e.useCallback((e,a)=>l(t=>(t.set(e,a),new Map(t))),[]),r=e.useCallback(e=>l(a=>a.has(e)?(a.delete(e),new Map(a)):a),[]),s=e.useCallback(()=>l(new Map),[]);return[t,n,r,s]};
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]};
@@ -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,l]=e.useState(a),n=e.useCallback((e,a)=>l(t=>(t.set(e,a),new Map(t))),[]),r=e.useCallback(e=>l(a=>a.has(e)?(a.delete(e),new Map(a)):a),[]),s=e.useCallback(()=>l(new Map),[]);return[t,n,r,s]};
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};
@@ -1,3 +1,4 @@
1
+ /** @see https://foxact.skk.moe/use-retimer */
1
2
  declare const useRetimer: () => (timerId: number) => void;
2
3
 
3
4
  export { useRetimer };
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),n=e.useCallback(e=>l(t=>t.has(e)?t:new Set([...t,e])),[]),r=e.useCallback(e=>l(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),s=e.useCallback(()=>l(new Set),[]);return[a,n,r,s]};
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]};
@@ -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),n=e.useCallback(e=>l(t=>t.has(e)?t:new Set([...t,e])),[]),r=e.useCallback(e=>l(t=>t.has(e)?(t.delete(e),new Set(t)):t),[]),s=e.useCallback(()=>l(new Set),[]);return[a,n,r,s]};
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};
@@ -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)},[])};
@@ -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 };
@@ -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)},[])};
@@ -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 };