@codeleap/hooks 7.0.1 → 7.0.2
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/index.js +57 -31
- package/dist/index.js.map +1 -1
- package/dist/onMount.js +7 -3
- package/dist/onMount.js.map +1 -1
- package/dist/onUpdate.js +7 -3
- package/dist/onUpdate.js.map +1 -1
- package/dist/useBooleanToggle.js +6 -3
- package/dist/useBooleanToggle.js.map +1 -1
- package/dist/useComponentTestId.js +8 -4
- package/dist/useComponentTestId.js.map +1 -1
- package/dist/useConditionalState.js +9 -5
- package/dist/useConditionalState.js.map +1 -1
- package/dist/useDebounce.js +8 -5
- package/dist/useDebounce.js.map +1 -1
- package/dist/useDebounceCallback.js +9 -6
- package/dist/useDebounceCallback.js.map +1 -1
- package/dist/useDerivedRef.js +8 -4
- package/dist/useDerivedRef.js.map +1 -1
- package/dist/useDerivedState.js +10 -6
- package/dist/useDerivedState.js.map +1 -1
- package/dist/useEffectOnce.js +7 -3
- package/dist/useEffectOnce.js.map +1 -1
- package/dist/useFilteredList.js +6 -3
- package/dist/useFilteredList.js.map +1 -1
- package/dist/useForceRender.js +6 -3
- package/dist/useForceRender.js.map +1 -1
- package/dist/useId.js +7 -4
- package/dist/useId.js.map +1 -1
- package/dist/useInterval.js +11 -8
- package/dist/useInterval.js.map +1 -1
- package/dist/useIsMounted.js +9 -5
- package/dist/useIsMounted.js.map +1 -1
- package/dist/useLazyStore.js +8 -5
- package/dist/useLazyStore.js.map +1 -1
- package/dist/useModal.js +8 -5
- package/dist/useModal.js.map +1 -1
- package/dist/useOptions.js +7 -4
- package/dist/useOptions.js.map +1 -1
- package/dist/usePartialState.js +9 -6
- package/dist/usePartialState.js.map +1 -1
- package/dist/usePlaces.js +20 -11
- package/dist/usePlaces.js.map +1 -1
- package/dist/usePlacesAutocompleteUtils.js +14 -7
- package/dist/usePlacesAutocompleteUtils.js.map +1 -1
- package/dist/usePrevious.js +8 -4
- package/dist/usePrevious.js.map +1 -1
- package/dist/usePromise.js +11 -7
- package/dist/usePromise.js.map +1 -1
- package/dist/useRenderCall.js +6 -3
- package/dist/useRenderCall.js.map +1 -1
- package/dist/useSearch/index.js +12 -9
- package/dist/useSearch/index.js.map +1 -1
- package/dist/useSearch/types.js +2 -1
- package/dist/useStableReference.js +8 -5
- package/dist/useStableReference.js.map +1 -1
- package/dist/useToggle.js +6 -3
- package/dist/useToggle.js.map +1 -1
- package/dist/useUncontrolled.js +8 -5
- package/dist/useUncontrolled.js.map +1 -1
- package/dist/useUnmount.js +9 -5
- package/dist/useUnmount.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,32 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.useReducer = exports.useDebugValue = exports.useLayoutEffect = exports.useContext = exports.useCallback = exports.useMemo = exports.useImperativeHandle = exports.useState = exports.useRef = exports.useEffect = void 0;
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return react_1.useEffect; } });
|
|
20
|
+
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return react_1.useRef; } });
|
|
21
|
+
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return react_1.useState; } });
|
|
22
|
+
Object.defineProperty(exports, "useImperativeHandle", { enumerable: true, get: function () { return react_1.useImperativeHandle; } });
|
|
23
|
+
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return react_1.useMemo; } });
|
|
24
|
+
Object.defineProperty(exports, "useCallback", { enumerable: true, get: function () { return react_1.useCallback; } });
|
|
25
|
+
Object.defineProperty(exports, "useContext", { enumerable: true, get: function () { return react_1.useContext; } });
|
|
26
|
+
Object.defineProperty(exports, "useLayoutEffect", { enumerable: true, get: function () { return react_1.useLayoutEffect; } });
|
|
27
|
+
Object.defineProperty(exports, "useDebugValue", { enumerable: true, get: function () { return react_1.useDebugValue; } });
|
|
28
|
+
Object.defineProperty(exports, "useReducer", { enumerable: true, get: function () { return react_1.useReducer; } });
|
|
29
|
+
__exportStar(require("./useConditionalState"), exports);
|
|
30
|
+
__exportStar(require("./usePromise"), exports);
|
|
31
|
+
__exportStar(require("./useUncontrolled"), exports);
|
|
32
|
+
__exportStar(require("./useForceRender"), exports);
|
|
33
|
+
__exportStar(require("./useDebounce"), exports);
|
|
34
|
+
__exportStar(require("./useInterval"), exports);
|
|
35
|
+
__exportStar(require("./onMount"), exports);
|
|
36
|
+
__exportStar(require("./onUpdate"), exports);
|
|
37
|
+
__exportStar(require("./usePrevious"), exports);
|
|
38
|
+
__exportStar(require("./useToggle"), exports);
|
|
39
|
+
__exportStar(require("./useBooleanToggle"), exports);
|
|
40
|
+
__exportStar(require("./useModal"), exports);
|
|
41
|
+
__exportStar(require("./usePlaces"), exports);
|
|
42
|
+
__exportStar(require("./usePlacesAutocompleteUtils"), exports);
|
|
43
|
+
__exportStar(require("./useEffectOnce"), exports);
|
|
44
|
+
__exportStar(require("./useUnmount"), exports);
|
|
45
|
+
__exportStar(require("./useSearch"), exports);
|
|
46
|
+
__exportStar(require("./usePartialState"), exports);
|
|
47
|
+
__exportStar(require("./useIsMounted"), exports);
|
|
48
|
+
__exportStar(require("./useComponentTestId"), exports);
|
|
49
|
+
__exportStar(require("./useId"), exports);
|
|
50
|
+
__exportStar(require("./useDebounceCallback"), exports);
|
|
51
|
+
__exportStar(require("./useDerivedRef"), exports);
|
|
52
|
+
__exportStar(require("./useDerivedState"), exports);
|
|
53
|
+
__exportStar(require("./useFilteredList"), exports);
|
|
54
|
+
__exportStar(require("./useLazyStore"), exports);
|
|
55
|
+
__exportStar(require("./useStableReference"), exports);
|
|
56
|
+
__exportStar(require("./useOptions"), exports);
|
|
57
|
+
__exportStar(require("./useRenderCall"), exports);
|
|
32
58
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAWc;AAiCZ,0FA3CA,iBAAS,OA2CA;AACT,uFA3CA,cAAM,OA2CA;AACN,yFA3CA,gBAAQ,OA2CA;AACR,oGA3CA,2BAAmB,OA2CA;AACnB,wFA3CA,eAAO,OA2CA;AACP,4FA3CA,mBAAW,OA2CA;AACX,2FA3CA,kBAAU,OA2CA;AACV,gGA3CA,uBAAe,OA2CA;AACf,8FA3CA,qBAAa,OA2CA;AACb,2FA3CA,kBAAU,OA2CA;AAxCZ,wDAAqC;AACrC,+CAA4B;AAC5B,oDAAiC;AACjC,mDAAgC;AAChC,gDAA6B;AAC7B,gDAA6B;AAC7B,4CAAyB;AACzB,6CAA0B;AAC1B,gDAA6B;AAC7B,8CAA2B;AAC3B,qDAAkC;AAClC,6CAA0B;AAC1B,8CAA2B;AAC3B,+DAA4C;AAC5C,kDAA+B;AAC/B,+CAA4B;AAC5B,8CAA2B;AAC3B,oDAAiC;AACjC,iDAA8B;AAC9B,uDAAoC;AACpC,0CAAuB;AACvB,wDAAqC;AACrC,kDAA+B;AAC/B,oDAAiC;AACjC,oDAAiC;AACjC,iDAA8B;AAC9B,uDAAoC;AACpC,+CAA4B;AAC5B,kDAA+B"}
|
package/dist/onMount.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onMount = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that runs a function once when the component mounts.
|
|
4
7
|
*
|
|
@@ -8,9 +11,10 @@ import { useEffect } from 'react';
|
|
|
8
11
|
* return () => console.log('Component unmounted')
|
|
9
12
|
* })
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
14
|
+
const onMount = (func) => {
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
13
16
|
return func();
|
|
14
17
|
}, []);
|
|
15
18
|
};
|
|
19
|
+
exports.onMount = onMount;
|
|
16
20
|
//# sourceMappingURL=onMount.js.map
|
package/dist/onMount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMount.js","sourceRoot":"","sources":["../src/onMount.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"onMount.js","sourceRoot":"","sources":["../src/onMount.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC;;;;;;;;GAQG;AACI,MAAM,OAAO,GAAG,CAAC,IAAiB,EAAE,EAAE;IAC3C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAJY,QAAA,OAAO,WAInB"}
|
package/dist/onUpdate.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onUpdate = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that runs a function when specified dependencies change.
|
|
4
7
|
*
|
|
@@ -7,9 +10,10 @@ import { useEffect } from 'react';
|
|
|
7
10
|
* console.log('Count changed:', count)
|
|
8
11
|
* }, [count])
|
|
9
12
|
*/
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
13
|
+
const onUpdate = (func, listeners = []) => {
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
12
15
|
return func();
|
|
13
16
|
}, listeners);
|
|
14
17
|
};
|
|
18
|
+
exports.onUpdate = onUpdate;
|
|
15
19
|
//# sourceMappingURL=onUpdate.js.map
|
package/dist/onUpdate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onUpdate.js","sourceRoot":"","sources":["../src/onUpdate.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"onUpdate.js","sourceRoot":"","sources":["../src/onUpdate.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,CAAC,IAAiB,EAAE,SAAS,GAAG,EAAE,EAAE,EAAE;IAC5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,EAAE,SAAS,CAAC,CAAA;AACf,CAAC,CAAA;AAJY,QAAA,QAAQ,YAIpB"}
|
package/dist/useBooleanToggle.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBooleanToggle = useBooleanToggle;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that manages a boolean state with toggle functionality.
|
|
4
7
|
*
|
|
@@ -7,8 +10,8 @@ import { useState } from 'react';
|
|
|
7
10
|
* toggleOpen() // Toggles the value
|
|
8
11
|
* toggleOpen(true) // Sets to true
|
|
9
12
|
*/
|
|
10
|
-
|
|
11
|
-
const [v, setV] = useState(initial);
|
|
13
|
+
function useBooleanToggle(initial) {
|
|
14
|
+
const [v, setV] = (0, react_1.useState)(initial);
|
|
12
15
|
function toggleOrSet(value) {
|
|
13
16
|
if (typeof value === 'boolean') {
|
|
14
17
|
setV(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBooleanToggle.js","sourceRoot":"","sources":["../src/useBooleanToggle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBooleanToggle.js","sourceRoot":"","sources":["../src/useBooleanToggle.ts"],"names":[],"mappings":";;AAUA,4CAYC;AAtBD,iCAAgC;AAEhC;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,OAAgB;IAC/C,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAA;IAEnC,SAAS,WAAW,CAAC,KAAe;QAClC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,CAAA;QACb,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC,EAAE,WAAW,CAAU,CAAA;AAClC,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useComponentTestId = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
const simpleHash = (str) => {
|
|
3
6
|
let hash = 0;
|
|
4
7
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -10,7 +13,7 @@ const simpleHash = (str) => {
|
|
|
10
13
|
const normalizeProps = (props, keys) => {
|
|
11
14
|
return keys.reduce((acc, key) => {
|
|
12
15
|
if (key === 'children') {
|
|
13
|
-
acc[key] = Children.map(props[key], (child) => typeof child === 'object' ? '[Component]' : child);
|
|
16
|
+
acc[key] = react_1.Children.map(props[key], (child) => typeof child === 'object' ? '[Component]' : child);
|
|
14
17
|
}
|
|
15
18
|
else {
|
|
16
19
|
acc[key] = props[key];
|
|
@@ -36,8 +39,9 @@ const generateComponentTestId = (componentName, props, keys) => {
|
|
|
36
39
|
* const testId = useComponentTestId(Button, props, ['label', 'variant'])
|
|
37
40
|
* // Returns: "Button:debug-name" or "Button:123456"
|
|
38
41
|
*/
|
|
39
|
-
|
|
40
|
-
const testIdRef = useRef(generateComponentTestId(Component.styleRegistryName, props, keys));
|
|
42
|
+
const useComponentTestId = (Component, props, keys) => {
|
|
43
|
+
const testIdRef = (0, react_1.useRef)(generateComponentTestId(Component.styleRegistryName, props, keys));
|
|
41
44
|
return testIdRef.current;
|
|
42
45
|
};
|
|
46
|
+
exports.useComponentTestId = useComponentTestId;
|
|
43
47
|
//# sourceMappingURL=useComponentTestId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useComponentTestId.js","sourceRoot":"","sources":["../src/useComponentTestId.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"useComponentTestId.js","sourceRoot":"","sources":["../src/useComponentTestId.ts"],"names":[],"mappings":";;;AACA,iCAAwC;AAExC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IACzC,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC7C,IAAI,IAAI,CAAC,CAAA;IACX,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAsB,KAAQ,EAAE,IAAoB,EAAc,EAAE;IACzF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACvB,GAAG,CAAC,GAAG,CAAC,GAAG,gBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAC/F,CAAA;QACH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAgB,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC/C,OAAO,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;AAC5D,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAsB,aAAqB,EAAE,KAAQ,EAAE,IAAoB,EAAE,EAAE;IAC7G,MAAM,YAAY,GAAG,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAA,KAAK,QAAQ,CAAA;IACzD,IAAI,YAAY;QAAE,OAAO,GAAG,aAAa,IAAI,kBAAkB,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC,EAAE,CAAA;IACnF,MAAM,cAAc,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAClD,OAAO,GAAG,aAAa,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,CAAA;AACzE,CAAC,CAAA;AAED;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,CAChC,SAAc,EACd,KAAQ,EACR,IAAoB,EACpB,EAAE;IACF,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,uBAAuB,CAAC,SAAS,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3F,OAAO,SAAS,CAAC,OAAO,CAAA;AAC1B,CAAC,CAAA;AAPY,QAAA,kBAAkB,sBAO9B"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConditionalState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useBooleanToggle_1 = require("./useBooleanToggle");
|
|
3
6
|
/**
|
|
4
7
|
* Hook that uses external state if provided, otherwise creates internal state.
|
|
5
8
|
* Useful for creating controlled/uncontrolled component patterns.
|
|
@@ -11,13 +14,14 @@ import { useBooleanToggle } from './useBooleanToggle';
|
|
|
11
14
|
* // Uncontrolled mode
|
|
12
15
|
* const [value, setValue] = useConditionalState(undefined, undefined, { initialValue: 'default' })
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
const useConditionalState = (value, setter, options = {}) => {
|
|
15
18
|
const state = (options === null || options === void 0 ? void 0 : options.isBooleanToggle)
|
|
16
|
-
? useBooleanToggle(options === null || options === void 0 ? void 0 : options.initialValue)
|
|
17
|
-
: useState(options === null || options === void 0 ? void 0 : options.initialValue);
|
|
19
|
+
? (0, useBooleanToggle_1.useBooleanToggle)(options === null || options === void 0 ? void 0 : options.initialValue)
|
|
20
|
+
: (0, react_1.useState)(options === null || options === void 0 ? void 0 : options.initialValue);
|
|
18
21
|
if (typeof value !== 'undefined' && typeof setter === 'function') {
|
|
19
22
|
return [value, setter];
|
|
20
23
|
}
|
|
21
24
|
return state;
|
|
22
25
|
};
|
|
26
|
+
exports.useConditionalState = useConditionalState;
|
|
23
27
|
//# sourceMappingURL=useConditionalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConditionalState.js","sourceRoot":"","sources":["../src/useConditionalState.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useConditionalState.js","sourceRoot":"","sources":["../src/useConditionalState.ts"],"names":[],"mappings":";;;AAAA,iCAA0D;AAE1D,yDAAqD;AASrD;;;;;;;;;;GAUG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAoB,EACpB,MAAmB,EACnB,UAAyC,EAAE,EACzB,EAAE;IACpB,MAAM,KAAK,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe;QACpC,CAAC,CAAC,IAAA,mCAAgB,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAuB,CAAC;QACpD,CAAC,CAAC,IAAA,gBAAQ,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC,CAAA;IAEnC,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,KAAoC,CAAA;AAC7C,CAAC,CAAA;AAdY,QAAA,mBAAmB,uBAc/B"}
|
package/dist/useDebounce.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = useDebounce;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that debounces a value, updating it after a specified delay.
|
|
4
7
|
*
|
|
@@ -6,15 +9,15 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
6
9
|
* const [debouncedSearch, resetDebounce] = useDebounce(searchTerm, 500)
|
|
7
10
|
* // debouncedSearch updates 500ms after searchTerm stops changing
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
11
|
-
const timeoutRef = useRef(null);
|
|
12
|
+
function useDebounce(value, debounce) {
|
|
13
|
+
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
|
|
14
|
+
const timeoutRef = (0, react_1.useRef)(null);
|
|
12
15
|
const reset = () => {
|
|
13
16
|
if (timeoutRef.current) {
|
|
14
17
|
clearTimeout(timeoutRef.current);
|
|
15
18
|
}
|
|
16
19
|
};
|
|
17
|
-
useEffect(() => {
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
18
21
|
timeoutRef.current = setTimeout(() => {
|
|
19
22
|
setDebouncedValue(value);
|
|
20
23
|
}, debounce);
|
package/dist/useDebounce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../src/useDebounce.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../src/useDebounce.ts"],"names":[],"mappings":";;AASA,kCAsBC;AA/BD,iCAAmD;AAEnD;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,KAAQ,EACR,QAAgB;IAEhB,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAE3D,MAAM,UAAU,GAAG,IAAA,cAAM,EAAuC,IAAI,CAAC,CAAA;IAErE,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAClC,CAAC;IACH,CAAC,CAAA;IACD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACnC,iBAAiB,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC,EAAE,QAAQ,CAAC,CAAA;QAEZ,OAAO,KAAK,CAAA;IACd,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounceCallback = useDebounceCallback;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that creates debounced, flush, and cancel functions for a callback.
|
|
4
7
|
*
|
|
@@ -11,20 +14,20 @@ import { useRef, useCallback } from 'react';
|
|
|
11
14
|
* flush('immediate') // Calls callback immediately
|
|
12
15
|
* cancel() // Cancels pending debounced call
|
|
13
16
|
*/
|
|
14
|
-
|
|
15
|
-
const timeoutRef = useRef(null);
|
|
16
|
-
const debounce = useCallback((...args) => {
|
|
17
|
+
function useDebounceCallback(callback, delay = 1000) {
|
|
18
|
+
const timeoutRef = (0, react_1.useRef)(null);
|
|
19
|
+
const debounce = (0, react_1.useCallback)((...args) => {
|
|
17
20
|
cancel();
|
|
18
21
|
timeoutRef.current = setTimeout(() => {
|
|
19
22
|
callback(...args);
|
|
20
23
|
timeoutRef.current = null;
|
|
21
24
|
}, delay);
|
|
22
25
|
}, [callback]);
|
|
23
|
-
const flush = useCallback((...args) => {
|
|
26
|
+
const flush = (0, react_1.useCallback)((...args) => {
|
|
24
27
|
cancel();
|
|
25
28
|
callback(...args);
|
|
26
29
|
}, [callback]);
|
|
27
|
-
const cancel = useCallback(() => {
|
|
30
|
+
const cancel = (0, react_1.useCallback)(() => {
|
|
28
31
|
if (timeoutRef.current) {
|
|
29
32
|
clearTimeout(timeoutRef.current);
|
|
30
33
|
timeoutRef.current = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounceCallback.js","sourceRoot":"","sources":["../src/useDebounceCallback.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDebounceCallback.js","sourceRoot":"","sources":["../src/useDebounceCallback.ts"],"names":[],"mappings":";;AAcA,kDAgCC;AA9CD,iCAA2C;AAE3C;;;;;;;;;;;GAWG;AACH,SAAgB,mBAAmB,CACjC,QAA8B,EAC9B,KAAK,GAAG,IAAI;IAEZ,MAAM,UAAU,GAAG,IAAA,cAAM,EAAuC,IAAI,CAAC,CAAA;IAErE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,IAAO,EAAE,EAAE;QAC1C,MAAM,EAAE,CAAA;QAER,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACnC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;YACjB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QAC3B,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,IAAO,EAAE,EAAE;QACvC,MAAM,EAAE,CAAA;QACR,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;IACnB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC9B,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;YAChC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/dist/useDerivedRef.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDerivedRef = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that creates a ref that automatically updates when a derived value changes.
|
|
4
7
|
*
|
|
@@ -6,11 +9,12 @@ import { useEffect, useRef } from 'react';
|
|
|
6
9
|
* const userNameRef = useDerivedRef(user, (u) => u.name)
|
|
7
10
|
* // userNameRef.current will always contain the latest user name
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
const ref = useRef(getValue(derivedValue));
|
|
11
|
-
useEffect(() => {
|
|
12
|
+
const useDerivedRef = (derivedValue, getValue) => {
|
|
13
|
+
const ref = (0, react_1.useRef)(getValue(derivedValue));
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
12
15
|
ref.current = getValue(derivedValue);
|
|
13
16
|
}, [derivedValue]);
|
|
14
17
|
return ref;
|
|
15
18
|
};
|
|
19
|
+
exports.useDerivedRef = useDerivedRef;
|
|
16
20
|
//# sourceMappingURL=useDerivedRef.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDerivedRef.js","sourceRoot":"","sources":["../src/useDerivedRef.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useDerivedRef.js","sourceRoot":"","sources":["../src/useDerivedRef.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AAEzC;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,CAC3B,YAAe,EACf,QAAgC,EACL,EAAE;IAC7B,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;IAE1C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;IACtC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAXY,QAAA,aAAa,iBAWzB"}
|
package/dist/useDerivedState.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDerivedState = void 0;
|
|
4
|
+
const utils_1 = require("@codeleap/utils");
|
|
5
|
+
const react_1 = require("react");
|
|
3
6
|
/**
|
|
4
7
|
* Hook that creates a state that synchronizes with a derived value, with customizable equality check.
|
|
5
8
|
*
|
|
@@ -9,10 +12,10 @@ import { useState, useEffect } from 'react';
|
|
|
9
12
|
* areEqual: (a, b) => a === b.id
|
|
10
13
|
* })
|
|
11
14
|
*/
|
|
12
|
-
|
|
13
|
-
const { getValue = (value) => value, transform = (value) => value, areEqual = (currentState, derivedValue) => deepEqual(currentState, derivedValue), } = options;
|
|
14
|
-
const [state, setState] = useState(() => getValue(derivedValue));
|
|
15
|
-
useEffect(() => {
|
|
15
|
+
const useDerivedState = (derivedValue, options = {}) => {
|
|
16
|
+
const { getValue = (value) => value, transform = (value) => value, areEqual = (currentState, derivedValue) => (0, utils_1.deepEqual)(currentState, derivedValue), } = options;
|
|
17
|
+
const [state, setState] = (0, react_1.useState)(() => getValue(derivedValue));
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
16
19
|
const newValue = getValue(derivedValue);
|
|
17
20
|
const stateAreEqual = areEqual(transform(state), transform(derivedValue));
|
|
18
21
|
if (!stateAreEqual) {
|
|
@@ -21,4 +24,5 @@ export const useDerivedState = (derivedValue, options = {}) => {
|
|
|
21
24
|
}, [derivedValue]);
|
|
22
25
|
return [state, setState];
|
|
23
26
|
};
|
|
27
|
+
exports.useDerivedState = useDerivedState;
|
|
24
28
|
//# sourceMappingURL=useDerivedState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDerivedState.js","sourceRoot":"","sources":["../src/useDerivedState.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useDerivedState.js","sourceRoot":"","sources":["../src/useDerivedState.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,iCAA2C;AAQ3C;;;;;;;;GAQG;AACI,MAAM,eAAe,GAAG,CAC7B,YAAe,EACf,UAAyB,EAAE,EACmB,EAAE;IAChD,MAAM,EACJ,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,KAAU,EACrC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAC5B,QAAQ,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,EAAE,CAAC,IAAA,iBAAS,EAAC,YAAY,EAAE,YAAY,CAAC,GACjF,GAAG,OAAO,CAAA;IAEX,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;IAEnE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;QAEvC,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAA;QAEzE,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC1B,CAAC,CAAA;AAvBY,QAAA,eAAe,mBAuB3B"}
|
package/dist/useEffectOnce.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useEffectOnce = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that runs an effect only once when the component mounts.
|
|
4
7
|
*
|
|
@@ -8,7 +11,8 @@ import { useEffect } from 'react';
|
|
|
8
11
|
* return () => console.log('Cleanup on unmount')
|
|
9
12
|
* })
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
useEffect(effect, []);
|
|
14
|
+
const useEffectOnce = (effect) => {
|
|
15
|
+
(0, react_1.useEffect)(effect, []);
|
|
13
16
|
};
|
|
17
|
+
exports.useEffectOnce = useEffectOnce;
|
|
14
18
|
//# sourceMappingURL=useEffectOnce.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEffectOnce.js","sourceRoot":"","sources":["../src/useEffectOnce.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useEffectOnce.js","sourceRoot":"","sources":["../src/useEffectOnce.ts"],"names":[],"mappings":";;;AAAA,iCAAiD;AAEjD;;;;;;;;GAQG;AACI,MAAM,aAAa,GAAG,CAAC,MAAsB,EAAE,EAAE;IACtD,IAAA,iBAAS,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACvB,CAAC,CAAA;AAFY,QAAA,aAAa,iBAEzB"}
|
package/dist/useFilteredList.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFilteredList = useFilteredList;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that filters out the first item from a list that matches a predicate.
|
|
4
7
|
*
|
|
@@ -6,8 +9,8 @@ import { useMemo } from 'react';
|
|
|
6
9
|
* const filteredUsers = useFilteredList(users, (user) => user.id === deletedId)
|
|
7
10
|
* // Returns users array without the first user matching the predicate
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
return useMemo(() => {
|
|
12
|
+
function useFilteredList(list, predicate) {
|
|
13
|
+
return (0, react_1.useMemo)(() => {
|
|
11
14
|
if (!list)
|
|
12
15
|
return [];
|
|
13
16
|
const index = list.findIndex(predicate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFilteredList.js","sourceRoot":"","sources":["../src/useFilteredList.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFilteredList.js","sourceRoot":"","sources":["../src/useFilteredList.ts"],"names":[],"mappings":";;AASA,0CAWC;AApBD,iCAA+B;AAE/B;;;;;;GAMG;AACH,SAAgB,eAAe,CAAI,IAAS,EAAE,SAA+B;IAC3E,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAA;QAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QACvC,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,OAAO,IAAI,CAAA;QAE7B,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACxB,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;AACvB,CAAC"}
|
package/dist/useForceRender.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useForceRender = useForceRender;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that returns a function to force a component re-render.
|
|
4
7
|
*
|
|
@@ -6,8 +9,8 @@ import { useReducer } from 'react';
|
|
|
6
9
|
* const forceRender = useForceRender()
|
|
7
10
|
* forceRender() // Forces component to re-render
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
const [_, forceRender] = useReducer((x) => x + 1, 0);
|
|
12
|
+
function useForceRender() {
|
|
13
|
+
const [_, forceRender] = (0, react_1.useReducer)((x) => x + 1, 0);
|
|
11
14
|
return forceRender;
|
|
12
15
|
}
|
|
13
16
|
//# sourceMappingURL=useForceRender.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForceRender.js","sourceRoot":"","sources":["../src/useForceRender.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useForceRender.js","sourceRoot":"","sources":["../src/useForceRender.ts"],"names":[],"mappings":";;AASA,wCAGC;AAZD,iCAAkC;AAElC;;;;;;GAMG;AACH,SAAgB,cAAc;IAC5B,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAA,kBAAU,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/dist/useId.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useId = useId;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that returns a stable ID, using provided ID if available or generating one.
|
|
4
7
|
*
|
|
@@ -6,10 +9,10 @@ import { useRef, useId as _useId } from 'react';
|
|
|
6
9
|
* const id = useId('custom-id') // Returns 'custom-id'
|
|
7
10
|
* const id = useId() // Returns generated ID like ':r1:'
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
function useId(id) {
|
|
10
13
|
var _a;
|
|
11
|
-
const defaultId =
|
|
12
|
-
const idRef = useRef(id);
|
|
14
|
+
const defaultId = (0, react_1.useId)();
|
|
15
|
+
const idRef = (0, react_1.useRef)(id);
|
|
13
16
|
return (_a = idRef.current) !== null && _a !== void 0 ? _a : defaultId;
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=useId.js.map
|
package/dist/useId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":";;AASA,sBAKC;AAdD,iCAA+C;AAE/C;;;;;;GAMG;AACH,SAAgB,KAAK,CAAI,EAAM;;IAC7B,MAAM,SAAS,GAAG,IAAA,aAAM,GAAE,CAAA;IAC1B,MAAM,KAAK,GAAG,IAAA,cAAM,EAAC,EAAE,CAAC,CAAA;IAExB,OAAO,MAAA,KAAK,CAAC,OAAO,mCAAI,SAAS,CAAA;AACnC,CAAC"}
|
package/dist/useInterval.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterval = useInterval;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Hook that manages an interval with start and clear controls.
|
|
4
7
|
* The handler receives a clear function to stop the interval from within.
|
|
@@ -12,19 +15,19 @@ import { useRef, useCallback, useEffect } from 'react';
|
|
|
12
15
|
* start() // Starts the interval
|
|
13
16
|
* clear() // Stops the interval
|
|
14
17
|
*/
|
|
15
|
-
|
|
16
|
-
const intervalRef = useRef(null);
|
|
17
|
-
const handlerRef = useRef(handler);
|
|
18
|
-
useEffect(() => {
|
|
18
|
+
function useInterval(handler, interval) {
|
|
19
|
+
const intervalRef = (0, react_1.useRef)(null);
|
|
20
|
+
const handlerRef = (0, react_1.useRef)(handler);
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
19
22
|
handlerRef.current = handler;
|
|
20
23
|
}, [handler]);
|
|
21
|
-
const clear = useCallback(() => {
|
|
24
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
22
25
|
if (intervalRef.current != null) {
|
|
23
26
|
clearInterval(intervalRef.current);
|
|
24
27
|
intervalRef.current = null;
|
|
25
28
|
}
|
|
26
29
|
}, []);
|
|
27
|
-
const start = useCallback(() => {
|
|
30
|
+
const start = (0, react_1.useCallback)(() => {
|
|
28
31
|
clear();
|
|
29
32
|
if (intervalRef.current == null) {
|
|
30
33
|
intervalRef.current = setInterval(() => {
|
|
@@ -32,7 +35,7 @@ export function useInterval(handler, interval) {
|
|
|
32
35
|
}, interval);
|
|
33
36
|
}
|
|
34
37
|
}, []);
|
|
35
|
-
useEffect(() => {
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
36
39
|
return () => {
|
|
37
40
|
clear();
|
|
38
41
|
};
|
package/dist/useInterval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":";;AAkBA,kCAoCC;AAtDD,iCAAsD;AAKtD;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CAAC,OAA2B,EAAE,QAAgB;IACvE,MAAM,WAAW,GAAG,IAAA,cAAM,EAAwC,IAAI,CAAC,CAAA;IACvE,MAAM,UAAU,GAAG,IAAA,cAAM,EAAqB,OAAO,CAAC,CAAA;IAEtD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC7B,IAAI,WAAW,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAChC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YAClC,WAAW,CAAC,OAAO,GAAG,IAAI,CAAA;QAC5B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC7B,KAAK,EAAE,CAAA;QAEP,IAAI,WAAW,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAChC,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;gBACrC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC,EAAE,QAAQ,CAAC,CAAA;QACd,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,KAAK,EAAE,CAAA;QACT,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO;QACL,KAAK;QACL,KAAK;QACL,QAAQ,EAAE,WAAW,CAAC,OAAO;KAC9B,CAAA;AACH,CAAC"}
|
package/dist/useIsMounted.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsMounted = useIsMounted;
|
|
4
|
+
exports.useIsClient = useIsClient;
|
|
5
|
+
const react_1 = require("react");
|
|
2
6
|
const isReactNativeOrServer = typeof navigator !== 'undefined';
|
|
3
|
-
const useIsomorphicLayoutEffect = isReactNativeOrServer ? useLayoutEffect : useEffect;
|
|
7
|
+
const useIsomorphicLayoutEffect = isReactNativeOrServer ? react_1.useLayoutEffect : react_1.useEffect;
|
|
4
8
|
/**
|
|
5
9
|
* Hook to check if the component has mounted. SSR safe.
|
|
6
10
|
*
|
|
@@ -10,8 +14,8 @@ const useIsomorphicLayoutEffect = isReactNativeOrServer ? useLayoutEffect : useE
|
|
|
10
14
|
* // Safe to use browser APIs
|
|
11
15
|
* }
|
|
12
16
|
*/
|
|
13
|
-
|
|
14
|
-
const [mounted, setMounted] = useState(false);
|
|
17
|
+
function useIsMounted() {
|
|
18
|
+
const [mounted, setMounted] = (0, react_1.useState)(false);
|
|
15
19
|
useIsomorphicLayoutEffect(() => {
|
|
16
20
|
setMounted(true);
|
|
17
21
|
}, []);
|
|
@@ -27,7 +31,7 @@ export function useIsMounted() {
|
|
|
27
31
|
* // Safe to use browser APIs
|
|
28
32
|
* }
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
function useIsClient() {
|
|
31
35
|
return {
|
|
32
36
|
isClient: useIsMounted(),
|
|
33
37
|
};
|