@mantine/hooks 7.0.1-alpha.0 → 7.0.1

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.
@@ -10,18 +10,21 @@ function useDebouncedState(defaultValue, wait, options = { leading: false }) {
10
10
  const leadingRef = React.useRef(true);
11
11
  const clearTimeout = () => window.clearTimeout(timeoutRef.current);
12
12
  React.useEffect(() => clearTimeout, []);
13
- const debouncedSetValue = React.useCallback((newValue) => {
14
- clearTimeout();
15
- if (leadingRef.current && options.leading) {
16
- setValue(newValue);
17
- } else {
18
- timeoutRef.current = window.setTimeout(() => {
19
- leadingRef.current = true;
13
+ const debouncedSetValue = React.useCallback(
14
+ (newValue) => {
15
+ clearTimeout();
16
+ if (leadingRef.current && options.leading) {
20
17
  setValue(newValue);
21
- }, wait);
22
- }
23
- leadingRef.current = false;
24
- }, [options.leading]);
18
+ } else {
19
+ timeoutRef.current = window.setTimeout(() => {
20
+ leadingRef.current = true;
21
+ setValue(newValue);
22
+ }, wait);
23
+ }
24
+ leadingRef.current = false;
25
+ },
26
+ [options.leading]
27
+ );
25
28
  return [value, debouncedSetValue];
26
29
  }
27
30
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-debounced-state.js","sources":["../../src/use-debounced-state/use-debounced-state.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from 'react';\n\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n wait: number,\n options = { leading: false }\n) {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = () => window.clearTimeout(timeoutRef.current!);\n useEffect(() => clearTimeout, []);\n\n const debouncedSetValue = useCallback((newValue: T) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, wait);\n }\n leadingRef.current = false;\n }, [options.leading]);\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":["useState","useRef","useEffect","useCallback"],"mappings":";;;;;;AACO,SAAS,iBAAiB,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AACpF,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,EAAE,MAAM,UAAU,GAAGC,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrE,EAAEC,eAAS,CAAC,MAAM,YAAY,EAAE,EAAE,CAAC,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAGC,iBAAW,CAAC,CAAC,QAAQ,KAAK;AACtD,IAAI,YAAY,EAAE,CAAC;AACnB,IAAI,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AAC/C,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACzB,KAAK,MAAM;AACX,MAAM,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACnD,QAAQ,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAClC,QAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3B,OAAO,EAAE,IAAI,CAAC,CAAC;AACf,KAAK;AACL,IAAI,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;AAC/B,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACxB,EAAE,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AACpC;;;;"}
1
+ {"version":3,"file":"use-debounced-state.js","sources":["../../src/use-debounced-state/use-debounced-state.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from 'react';\n\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n wait: number,\n options = { leading: false }\n) {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = () => window.clearTimeout(timeoutRef.current!);\n useEffect(() => clearTimeout, []);\n\n const debouncedSetValue = useCallback(\n (newValue: T) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, wait);\n }\n leadingRef.current = false;\n },\n [options.leading]\n );\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":["useState","useRef","useEffect","useCallback"],"mappings":";;;;;;AACO,SAAS,iBAAiB,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AACpF,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,EAAE,MAAM,UAAU,GAAGC,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrE,EAAEC,eAAS,CAAC,MAAM,YAAY,EAAE,EAAE,CAAC,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAGC,iBAAW;AACvC,IAAI,CAAC,QAAQ,KAAK;AAClB,MAAM,YAAY,EAAE,CAAC;AACrB,MAAM,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AACjD,QAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3B,OAAO,MAAM;AACb,QAAQ,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACrD,UAAU,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AACpC,UAAU,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7B,SAAS,EAAE,IAAI,CAAC,CAAC;AACjB,OAAO;AACP,MAAM,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;AACjC,KAAK;AACL,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;AACrB,GAAG,CAAC;AACJ,EAAE,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AACpC;;;;"}
package/esm/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  export { useCallbackRef } from './use-callback-ref/use-callback-ref.mjs';
2
3
  export { useDebounceCallback } from './use-debounced-callback/use-debounced-callback.mjs';
3
4
  export { useClickOutside } from './use-click-outside/use-click-outside.mjs';
package/esm/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -6,18 +6,21 @@ function useDebouncedState(defaultValue, wait, options = { leading: false }) {
6
6
  const leadingRef = useRef(true);
7
7
  const clearTimeout = () => window.clearTimeout(timeoutRef.current);
8
8
  useEffect(() => clearTimeout, []);
9
- const debouncedSetValue = useCallback((newValue) => {
10
- clearTimeout();
11
- if (leadingRef.current && options.leading) {
12
- setValue(newValue);
13
- } else {
14
- timeoutRef.current = window.setTimeout(() => {
15
- leadingRef.current = true;
9
+ const debouncedSetValue = useCallback(
10
+ (newValue) => {
11
+ clearTimeout();
12
+ if (leadingRef.current && options.leading) {
16
13
  setValue(newValue);
17
- }, wait);
18
- }
19
- leadingRef.current = false;
20
- }, [options.leading]);
14
+ } else {
15
+ timeoutRef.current = window.setTimeout(() => {
16
+ leadingRef.current = true;
17
+ setValue(newValue);
18
+ }, wait);
19
+ }
20
+ leadingRef.current = false;
21
+ },
22
+ [options.leading]
23
+ );
21
24
  return [value, debouncedSetValue];
22
25
  }
23
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-debounced-state.mjs","sources":["../../src/use-debounced-state/use-debounced-state.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from 'react';\n\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n wait: number,\n options = { leading: false }\n) {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = () => window.clearTimeout(timeoutRef.current!);\n useEffect(() => clearTimeout, []);\n\n const debouncedSetValue = useCallback((newValue: T) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, wait);\n }\n leadingRef.current = false;\n }, [options.leading]);\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,iBAAiB,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AACpF,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrE,EAAE,SAAS,CAAC,MAAM,YAAY,EAAE,EAAE,CAAC,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAG,WAAW,CAAC,CAAC,QAAQ,KAAK;AACtD,IAAI,YAAY,EAAE,CAAC;AACnB,IAAI,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AAC/C,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACzB,KAAK,MAAM;AACX,MAAM,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACnD,QAAQ,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAClC,QAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3B,OAAO,EAAE,IAAI,CAAC,CAAC;AACf,KAAK;AACL,IAAI,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;AAC/B,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACxB,EAAE,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AACpC;;;;"}
1
+ {"version":3,"file":"use-debounced-state.mjs","sources":["../../src/use-debounced-state/use-debounced-state.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from 'react';\n\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n wait: number,\n options = { leading: false }\n) {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = () => window.clearTimeout(timeoutRef.current!);\n useEffect(() => clearTimeout, []);\n\n const debouncedSetValue = useCallback(\n (newValue: T) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, wait);\n }\n leadingRef.current = false;\n },\n [options.leading]\n );\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,iBAAiB,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AACpF,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrE,EAAE,SAAS,CAAC,MAAM,YAAY,EAAE,EAAE,CAAC,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAG,WAAW;AACvC,IAAI,CAAC,QAAQ,KAAK;AAClB,MAAM,YAAY,EAAE,CAAC;AACrB,MAAM,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AACjD,QAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3B,OAAO,MAAM;AACb,QAAQ,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACrD,UAAU,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AACpC,UAAU,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7B,SAAS,EAAE,IAAI,CAAC,CAAC;AACjB,OAAO;AACP,MAAM,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;AACjC,KAAK;AACL,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;AACrB,GAAG,CAAC;AACJ,EAAE,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AACpC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/hooks",
3
- "version": "7.0.1-alpha.0",
3
+ "version": "7.0.1",
4
4
  "main": "./cjs/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "module": "./esm/index.mjs",