@dxos/react-hooks 0.8.3 → 0.8.4-main.1da679c
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/dist/lib/browser/index.mjs +185 -77
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +185 -77
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +4 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useAsyncEffect.d.ts +5 -29
- package/dist/types/src/useAsyncEffect.d.ts.map +1 -1
- package/dist/types/src/useAsyncEffect.stories.d.ts +9 -0
- package/dist/types/src/useAsyncEffect.stories.d.ts.map +1 -0
- package/dist/types/src/useAsyncState.d.ts.map +1 -1
- package/dist/types/src/useControlledState.d.ts +2 -1
- package/dist/types/src/useControlledState.d.ts.map +1 -1
- package/dist/types/src/useDebugDeps.d.ts +6 -0
- package/dist/types/src/useDebugDeps.d.ts.map +1 -0
- package/dist/types/src/useDefaultValue.d.ts.map +1 -1
- package/dist/types/src/useDefaults.d.ts +6 -0
- package/dist/types/src/useDefaults.d.ts.map +1 -0
- package/dist/types/src/useDynamicRef.d.ts +6 -1
- package/dist/types/src/useDynamicRef.d.ts.map +1 -1
- package/dist/types/src/useForwardedRef.d.ts +1 -1
- package/dist/types/src/useIsFocused.d.ts.map +1 -1
- package/dist/types/src/useSignals.d.ts +10 -0
- package/dist/types/src/useSignals.d.ts.map +1 -0
- package/dist/types/src/useTimeout.d.ts +3 -0
- package/dist/types/src/useTimeout.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/src/index.ts +4 -1
- package/src/useAsyncEffect.stories.tsx +34 -0
- package/src/useAsyncEffect.ts +19 -49
- package/src/useAsyncState.ts +2 -1
- package/src/useControlledState.ts +10 -1
- package/src/useDebugDeps.ts +26 -0
- package/src/useDefaultValue.ts +1 -2
- package/src/useDefaults.ts +14 -0
- package/src/useDynamicRef.ts +27 -5
- package/src/useForwardedRef.ts +2 -2
- package/src/useIsFocused.ts +1 -1
- package/src/useSignals.ts +27 -0
- package/src/useTimeout.ts +46 -0
- package/src/useTrackProps.ts +1 -1
- package/src/useTransitions.ts +1 -1
- package/dist/lib/node/index.cjs +0 -413
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/types/src/useAsyncEffect.test.d.ts +0 -2
- package/dist/types/src/useAsyncEffect.test.d.ts.map +0 -1
- package/dist/types/src/useDebugReactDeps.d.ts +0 -6
- package/dist/types/src/useDebugReactDeps.d.ts.map +0 -1
- package/src/useAsyncEffect.test.tsx +0 -51
- package/src/useDebugReactDeps.ts +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-hooks",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1da679c",
|
|
4
4
|
"description": "React hooks supporting DXOS React primitives.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -26,10 +27,12 @@
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@preact-signals/safe-react": "^0.9.0",
|
|
28
29
|
"alea": "^1.0.1",
|
|
29
|
-
"
|
|
30
|
-
"@dxos/
|
|
30
|
+
"lodash.defaultsdeep": "^4.6.1",
|
|
31
|
+
"@dxos/async": "0.8.4-main.1da679c",
|
|
32
|
+
"@dxos/log": "0.8.4-main.1da679c"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
35
|
+
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
33
36
|
"@types/react": "~18.2.0",
|
|
34
37
|
"@types/react-dom": "~18.2.0",
|
|
35
38
|
"react": "~18.2.0",
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
export * from './useAsyncEffect';
|
|
6
6
|
export * from './useAsyncState';
|
|
7
7
|
export * from './useControlledState';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './useDebugDeps';
|
|
9
9
|
export * from './useDefaultValue';
|
|
10
|
+
export * from './useDefaults';
|
|
10
11
|
export * from './useDynamicRef';
|
|
11
12
|
export * from './useFileDownload';
|
|
12
13
|
export * from './useForwardedRef';
|
|
@@ -16,5 +17,7 @@ export * from './useMediaQuery';
|
|
|
16
17
|
export * from './useMulticastObservable';
|
|
17
18
|
export * from './useRefCallback';
|
|
18
19
|
export * from './useResize';
|
|
20
|
+
export * from './useSignals';
|
|
21
|
+
export * from './useTimeout';
|
|
19
22
|
export * from './useTrackProps';
|
|
20
23
|
export * from './useTransitions';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
+
import React, { useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { sleep } from '@dxos/async';
|
|
11
|
+
|
|
12
|
+
import { useAsyncEffect } from './useAsyncEffect';
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
title: 'ui/react-hooks/useAsyncEffect',
|
|
16
|
+
} satisfies Meta;
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
render: () => {
|
|
24
|
+
const [value, setValue] = useState(0);
|
|
25
|
+
useAsyncEffect(async (controller) => {
|
|
26
|
+
await sleep(100);
|
|
27
|
+
if (!controller.signal.aborted) {
|
|
28
|
+
setValue((value) => value + 1);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
return <div>{value}</div>;
|
|
33
|
+
},
|
|
34
|
+
};
|
package/src/useAsyncEffect.ts
CHANGED
|
@@ -2,61 +2,31 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useEffect } from 'react';
|
|
6
|
-
|
|
7
|
-
import { log } from '@dxos/log';
|
|
5
|
+
import { type DependencyList, type EffectCallback, useEffect } from 'react';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* ```tsx
|
|
14
|
-
* useAsyncEffect(async () => {
|
|
15
|
-
* await test();
|
|
16
|
-
* }, []);
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* The callback may check of the component is still mounted before doing state updates.
|
|
20
|
-
*
|
|
21
|
-
* ```tsx
|
|
22
|
-
* const [value, setValue] = useState<string>();
|
|
23
|
-
* useAsyncEffect<string>(async (isMounted) => {
|
|
24
|
-
* const value = await test();
|
|
25
|
-
* if (!isMounted()) {
|
|
26
|
-
* setValue(value);
|
|
27
|
-
* }
|
|
28
|
-
* }, () => console.log('Unmounted'), []);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @param callback Receives a getter function that determines if the component is still mounted.
|
|
32
|
-
* @param destructor Receives the value returned from the callback.
|
|
33
|
-
* @param deps
|
|
34
|
-
*
|
|
35
|
-
* NOTE: This effect does not cancel the async operation if the component is unmounted.
|
|
36
|
-
*
|
|
37
|
-
* @deprecated
|
|
8
|
+
* Async version of useEffect.
|
|
9
|
+
* The `AbortController` can be used to detect if the component has been unmounted and
|
|
10
|
+
* can be used to propagate abort signals to downstream async operations (e.g., `fetch`).
|
|
38
11
|
*/
|
|
39
|
-
export const useAsyncEffect =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
deps?: any[],
|
|
12
|
+
export const useAsyncEffect = (
|
|
13
|
+
cb: (controller: AbortController) => Promise<EffectCallback | void>,
|
|
14
|
+
deps?: DependencyList,
|
|
43
15
|
) => {
|
|
44
|
-
const [effectDestructor, effectDeps] =
|
|
45
|
-
typeof destructor === 'function' ? [destructor, deps] : [undefined, destructor];
|
|
46
|
-
|
|
47
16
|
useEffect(() => {
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
let cleanup: EffectCallback | void;
|
|
19
|
+
// NOTE: Timeout enables us to immediately cancel. if the component is unmounted.
|
|
20
|
+
const t = setTimeout(async () => {
|
|
21
|
+
if (!controller.signal.aborted) {
|
|
22
|
+
cleanup = await cb(controller);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
56
25
|
|
|
57
26
|
return () => {
|
|
58
|
-
|
|
59
|
-
|
|
27
|
+
clearTimeout(t);
|
|
28
|
+
controller.abort();
|
|
29
|
+
cleanup?.();
|
|
60
30
|
};
|
|
61
|
-
},
|
|
31
|
+
}, deps ?? []);
|
|
62
32
|
};
|
package/src/useAsyncState.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const useAsyncState = <T>(
|
|
|
14
14
|
const [value, setValue] = useState<T | undefined>();
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
let disposed = false;
|
|
17
|
-
|
|
17
|
+
const t = setTimeout(async () => {
|
|
18
18
|
const data = await cb();
|
|
19
19
|
if (!disposed) {
|
|
20
20
|
setValue(data);
|
|
@@ -23,6 +23,7 @@ export const useAsyncState = <T>(
|
|
|
23
23
|
|
|
24
24
|
return () => {
|
|
25
25
|
disposed = true;
|
|
26
|
+
clearTimeout(t);
|
|
26
27
|
};
|
|
27
28
|
}, deps);
|
|
28
29
|
|
|
@@ -6,8 +6,13 @@ import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A stateful hook with a controlled value.
|
|
9
|
+
* NOTE: Be careful not to provide an inlinde default array.
|
|
9
10
|
*/
|
|
10
|
-
export const useControlledState = <T>(
|
|
11
|
+
export const useControlledState = <T>(
|
|
12
|
+
controlledValue: T,
|
|
13
|
+
onChange?: (value: T) => void,
|
|
14
|
+
...deps: any[]
|
|
15
|
+
): [T, Dispatch<SetStateAction<T>>] => {
|
|
11
16
|
const [value, setValue] = useState<T>(controlledValue);
|
|
12
17
|
useEffect(() => {
|
|
13
18
|
if (controlledValue !== undefined) {
|
|
@@ -15,5 +20,9 @@ export const useControlledState = <T>(controlledValue: T, ...deps: any[]): [T, D
|
|
|
15
20
|
}
|
|
16
21
|
}, [controlledValue, ...deps]);
|
|
17
22
|
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
onChange?.(value);
|
|
25
|
+
}, [value, onChange]);
|
|
26
|
+
|
|
18
27
|
return [value, setValue];
|
|
19
28
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type DependencyList, useEffect, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Util to log deps that have changed.
|
|
9
|
+
*/
|
|
10
|
+
export const useDebugDeps = (deps: DependencyList = []) => {
|
|
11
|
+
const lastDeps = useRef<DependencyList>([]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
console.group('deps changed', { previous: lastDeps.current.length, current: deps.length });
|
|
14
|
+
for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {
|
|
15
|
+
if (lastDeps.current[i] !== deps[i]) {
|
|
16
|
+
console.log('changed', {
|
|
17
|
+
index: i,
|
|
18
|
+
previous: lastDeps.current[i],
|
|
19
|
+
current: deps[i],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
console.groupEnd();
|
|
24
|
+
lastDeps.current = deps;
|
|
25
|
+
}, deps);
|
|
26
|
+
};
|
package/src/useDefaultValue.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useEffect,
|
|
5
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A custom React hook that provides a stable default value for a potentially undefined reactive value.
|
|
@@ -21,7 +21,6 @@ export const useDefaultValue = <T>(reactiveValue: T | undefined | null, getDefau
|
|
|
21
21
|
// regardless of whether the defaultValue changes.
|
|
22
22
|
const stableDefaultValue = useMemo(getDefaultValue, []);
|
|
23
23
|
const [value, setValue] = useState(reactiveValue ?? stableDefaultValue);
|
|
24
|
-
|
|
25
24
|
useEffect(() => {
|
|
26
25
|
setValue(reactiveValue ?? stableDefaultValue);
|
|
27
26
|
}, [reactiveValue, stableDefaultValue]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a memo-ized deep-merged object of the default and value.
|
|
10
|
+
* If value is undefined or null, then returns the default.
|
|
11
|
+
*/
|
|
12
|
+
export const useDefaults = <T>(value: T | undefined | null, defaults: T): T => {
|
|
13
|
+
return useMemo(() => defaultsDeep({}, defaults, value), [value, defaults]);
|
|
14
|
+
};
|
package/src/useDynamicRef.ts
CHANGED
|
@@ -2,16 +2,38 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useCallback } from '@preact-signals/safe-react/react';
|
|
6
|
+
import { type Dispatch, type MutableRefObject, type SetStateAction, useEffect, useRef, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Like `useState` but with an additional dynamic value.
|
|
10
|
+
*/
|
|
11
|
+
export const useStateWithRef = <T>(value$: T): [T, Dispatch<SetStateAction<T>>, MutableRefObject<T>] => {
|
|
12
|
+
const [value, setValue] = useState<T>(value$);
|
|
13
|
+
const valueRef = useRef<T>(value$);
|
|
14
|
+
const setter = useCallback<Dispatch<SetStateAction<T>>>((value) => {
|
|
15
|
+
if (typeof value === 'function') {
|
|
16
|
+
setValue((current) => {
|
|
17
|
+
valueRef.current = (value as Function)(current);
|
|
18
|
+
return valueRef.current;
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
valueRef.current = value;
|
|
22
|
+
setValue(value);
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
return [value, setter, valueRef];
|
|
27
|
+
};
|
|
6
28
|
|
|
7
29
|
/**
|
|
8
30
|
* Ref that is updated by a dependency.
|
|
9
31
|
*/
|
|
10
|
-
export const useDynamicRef = <T>(value: T) => {
|
|
11
|
-
const
|
|
32
|
+
export const useDynamicRef = <T>(value: T): MutableRefObject<T> => {
|
|
33
|
+
const valueRef = useRef<T>(value);
|
|
12
34
|
useEffect(() => {
|
|
13
|
-
|
|
35
|
+
valueRef.current = value;
|
|
14
36
|
}, [value]);
|
|
15
37
|
|
|
16
|
-
return
|
|
38
|
+
return valueRef;
|
|
17
39
|
};
|
package/src/useForwardedRef.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type ForwardedRef,
|
|
5
|
+
import { type ForwardedRef, useEffect, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Combines a possibly undefined forwarded ref with a locally defined ref.
|
|
9
|
-
*
|
|
9
|
+
* @deprecated Use @radix-ui/react-compose-refs
|
|
10
10
|
*/
|
|
11
11
|
export const useForwardedRef = <T>(ref: ForwardedRef<T>) => {
|
|
12
12
|
const innerRef = useRef<T>(null);
|
package/src/useIsFocused.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Based upon the useIsFocused hook which is part of the `rci` project:
|
|
6
6
|
/// https://github.com/leonardodino/rci/blob/main/packages/use-is-focused
|
|
7
7
|
|
|
8
|
-
import { useEffect, useRef, useState
|
|
8
|
+
import { type RefObject, useEffect, useRef, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
export const useIsFocused = (inputRef: RefObject<HTMLInputElement>) => {
|
|
11
11
|
const [isFocused, setIsFocused] = useState<boolean | undefined>(undefined);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { computed, effect } from '@preact-signals/safe-react';
|
|
6
|
+
import { useRef } from '@preact-signals/safe-react/react';
|
|
7
|
+
import { type DependencyList, useEffect, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Like `useEffect` but also tracks signals inside of the callback.
|
|
11
|
+
*/
|
|
12
|
+
export const useSignalsEffect = (cb: () => void | (() => void), deps?: DependencyList) => {
|
|
13
|
+
const callback = useRef(cb);
|
|
14
|
+
callback.current = cb;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
return effect(() => {
|
|
17
|
+
return callback.current();
|
|
18
|
+
});
|
|
19
|
+
}, deps ?? []);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Like `useMemo` but also tracks signals inside of the callback.
|
|
24
|
+
*/
|
|
25
|
+
export const useSignalsMemo = <T>(cb: () => T, deps?: DependencyList) => {
|
|
26
|
+
return useMemo(() => computed(cb), deps ?? []).value;
|
|
27
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
export const useTimeout = (callback?: () => Promise<void>, delay = 0, deps: any[] = []) => {
|
|
8
|
+
const callbackRef = useRef(callback);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
callbackRef.current = callback;
|
|
11
|
+
}, [callback]);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (delay == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const t = setTimeout(() => callbackRef.current?.(), delay);
|
|
19
|
+
return () => clearTimeout(t);
|
|
20
|
+
}, [delay, ...deps]);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const useInterval = (
|
|
24
|
+
callback?: (() => Promise<void | boolean>) | (() => void | boolean),
|
|
25
|
+
delay = 0,
|
|
26
|
+
deps: any[] = [],
|
|
27
|
+
) => {
|
|
28
|
+
const callbackRef = useRef(callback);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
callbackRef.current = callback;
|
|
31
|
+
}, [callback]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (delay == null) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const i = setInterval(async () => {
|
|
39
|
+
const result = await callbackRef.current?.();
|
|
40
|
+
if (result === false) {
|
|
41
|
+
clearInterval(i);
|
|
42
|
+
}
|
|
43
|
+
}, delay);
|
|
44
|
+
return () => clearInterval(i);
|
|
45
|
+
}, [delay, ...deps]);
|
|
46
|
+
};
|
package/src/useTrackProps.ts
CHANGED
package/src/useTransitions.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
const isFunction = <T>(functionToCheck: any): functionToCheck is (value: T) => boolean => {
|
|
8
8
|
return functionToCheck instanceof Function;
|