react-simplikit 0.0.15 → 0.0.17
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 +1 -0
- package/dist/hooks/useBooleanState/index.cjs +1 -1
- package/dist/hooks/usePrevious/index.cjs +5 -5
- package/dist/index.cjs +6 -6
- package/esm/hooks/useBooleanState/index.js +1 -1
- package/esm/hooks/usePrevious/index.js +6 -6
- package/esm/index.js +11 -11
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ English | [Korean](./README-ko_kr.md)
|
|
|
16
16
|
import { useBooleanState } from 'react-simplikit';
|
|
17
17
|
|
|
18
18
|
function Component() {
|
|
19
|
+
// using the `useBooleanState` hook to manage state.
|
|
19
20
|
const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] = useBooleanState(false);
|
|
20
21
|
|
|
21
22
|
return (
|
|
@@ -31,14 +31,14 @@ function usePrevious(state, compare = strictEquals) {
|
|
|
31
31
|
const prevRef = (0, import_react.useRef)(state);
|
|
32
32
|
const currentRef = (0, import_react.useRef)(state);
|
|
33
33
|
const isFirstRender = (0, import_react.useRef)(true);
|
|
34
|
-
(
|
|
34
|
+
if (isFirstRender.current) {
|
|
35
35
|
isFirstRender.current = false;
|
|
36
|
-
}, []);
|
|
37
|
-
if (isFirstRender.current || compare(currentRef.current, state)) {
|
|
38
36
|
return prevRef.current;
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (!compare(currentRef.current, state)) {
|
|
39
|
+
prevRef.current = currentRef.current;
|
|
40
|
+
currentRef.current = state;
|
|
41
|
+
}
|
|
42
42
|
return prevRef.current;
|
|
43
43
|
}
|
|
44
44
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.cjs
CHANGED
|
@@ -353,7 +353,7 @@ var useBooleanState = (defaultValue = false) => {
|
|
|
353
353
|
setBool(false);
|
|
354
354
|
}, []);
|
|
355
355
|
const toggle2 = (0, import_react9.useCallback)(() => {
|
|
356
|
-
setBool((
|
|
356
|
+
setBool((prevBool) => !prevBool);
|
|
357
357
|
}, []);
|
|
358
358
|
return [bool, setTrue, setFalse, toggle2];
|
|
359
359
|
};
|
|
@@ -519,14 +519,14 @@ function usePrevious(state, compare = strictEquals) {
|
|
|
519
519
|
const prevRef = (0, import_react18.useRef)(state);
|
|
520
520
|
const currentRef = (0, import_react18.useRef)(state);
|
|
521
521
|
const isFirstRender = (0, import_react18.useRef)(true);
|
|
522
|
-
(
|
|
522
|
+
if (isFirstRender.current) {
|
|
523
523
|
isFirstRender.current = false;
|
|
524
|
-
}, []);
|
|
525
|
-
if (isFirstRender.current || compare(currentRef.current, state)) {
|
|
526
524
|
return prevRef.current;
|
|
527
525
|
}
|
|
528
|
-
|
|
529
|
-
|
|
526
|
+
if (!compare(currentRef.current, state)) {
|
|
527
|
+
prevRef.current = currentRef.current;
|
|
528
|
+
currentRef.current = state;
|
|
529
|
+
}
|
|
530
530
|
return prevRef.current;
|
|
531
531
|
}
|
|
532
532
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// src/hooks/usePrevious/usePrevious.ts
|
|
2
|
-
import {
|
|
2
|
+
import { useRef } from "react";
|
|
3
3
|
var strictEquals = (prev, next) => prev === next;
|
|
4
4
|
function usePrevious(state, compare = strictEquals) {
|
|
5
5
|
const prevRef = useRef(state);
|
|
6
6
|
const currentRef = useRef(state);
|
|
7
7
|
const isFirstRender = useRef(true);
|
|
8
|
-
|
|
8
|
+
if (isFirstRender.current) {
|
|
9
9
|
isFirstRender.current = false;
|
|
10
|
-
}, []);
|
|
11
|
-
if (isFirstRender.current || compare(currentRef.current, state)) {
|
|
12
10
|
return prevRef.current;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
if (!compare(currentRef.current, state)) {
|
|
13
|
+
prevRef.current = currentRef.current;
|
|
14
|
+
currentRef.current = state;
|
|
15
|
+
}
|
|
16
16
|
return prevRef.current;
|
|
17
17
|
}
|
|
18
18
|
export {
|
package/esm/index.js
CHANGED
|
@@ -304,7 +304,7 @@ var useBooleanState = (defaultValue = false) => {
|
|
|
304
304
|
setBool(false);
|
|
305
305
|
}, []);
|
|
306
306
|
const toggle2 = useCallback5(() => {
|
|
307
|
-
setBool((
|
|
307
|
+
setBool((prevBool) => !prevBool);
|
|
308
308
|
}, []);
|
|
309
309
|
return [bool, setTrue, setFalse, toggle2];
|
|
310
310
|
};
|
|
@@ -464,20 +464,20 @@ function areDeeplyEqual(x, y) {
|
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
// src/hooks/usePrevious/usePrevious.ts
|
|
467
|
-
import {
|
|
467
|
+
import { useRef as useRef9 } from "react";
|
|
468
468
|
var strictEquals = (prev, next) => prev === next;
|
|
469
469
|
function usePrevious(state, compare = strictEquals) {
|
|
470
470
|
const prevRef = useRef9(state);
|
|
471
471
|
const currentRef = useRef9(state);
|
|
472
472
|
const isFirstRender = useRef9(true);
|
|
473
|
-
|
|
473
|
+
if (isFirstRender.current) {
|
|
474
474
|
isFirstRender.current = false;
|
|
475
|
-
}, []);
|
|
476
|
-
if (isFirstRender.current || compare(currentRef.current, state)) {
|
|
477
475
|
return prevRef.current;
|
|
478
476
|
}
|
|
479
|
-
|
|
480
|
-
|
|
477
|
+
if (!compare(currentRef.current, state)) {
|
|
478
|
+
prevRef.current = currentRef.current;
|
|
479
|
+
currentRef.current = state;
|
|
480
|
+
}
|
|
481
481
|
return prevRef.current;
|
|
482
482
|
}
|
|
483
483
|
|
|
@@ -621,7 +621,7 @@ function useStorageState(key, { storage = safeLocalStorage, defaultValue } = {})
|
|
|
621
621
|
}
|
|
622
622
|
|
|
623
623
|
// src/hooks/useThrottle/useThrottle.ts
|
|
624
|
-
import { useEffect as
|
|
624
|
+
import { useEffect as useEffect10, useMemo as useMemo6 } from "react";
|
|
625
625
|
|
|
626
626
|
// src/hooks/useThrottle/throttle.ts
|
|
627
627
|
function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
|
|
@@ -651,7 +651,7 @@ function useThrottle(callback, wait, options) {
|
|
|
651
651
|
() => throttle(preservedCallback, wait, preservedOptions),
|
|
652
652
|
[preservedOptions, preservedCallback, wait]
|
|
653
653
|
);
|
|
654
|
-
|
|
654
|
+
useEffect10(() => {
|
|
655
655
|
return () => {
|
|
656
656
|
throttledCallback.cancel();
|
|
657
657
|
};
|
|
@@ -660,10 +660,10 @@ function useThrottle(callback, wait, options) {
|
|
|
660
660
|
}
|
|
661
661
|
|
|
662
662
|
// src/hooks/useTimeout/useTimeout.ts
|
|
663
|
-
import { useEffect as
|
|
663
|
+
import { useEffect as useEffect11 } from "react";
|
|
664
664
|
function useTimeout(callback, delay = 0) {
|
|
665
665
|
const preservedCallback = usePreservedCallback(callback);
|
|
666
|
-
|
|
666
|
+
useEffect11(() => {
|
|
667
667
|
const timeoutId = window.setTimeout(preservedCallback, delay);
|
|
668
668
|
return () => window.clearTimeout(timeoutId);
|
|
669
669
|
}, [delay, preservedCallback]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-simplikit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -24,11 +24,15 @@
|
|
|
24
24
|
"docs:dev": "vitepress dev",
|
|
25
25
|
"docs:build": "vitepress build",
|
|
26
26
|
"docs:preview": "vitepress preview",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"test": "
|
|
31
|
-
"test:
|
|
27
|
+
"fix": "yarn run fix:lint && yarn run fix:format",
|
|
28
|
+
"fix:format": "prettier . --write",
|
|
29
|
+
"fix:lint": "eslint src --fix",
|
|
30
|
+
"test": "yarn run test:lint && yarn run test:format && yarn run test:type && yarn run test:spec && yarn run test:coverage",
|
|
31
|
+
"test:format": "prettier . --list-different",
|
|
32
|
+
"test:lint": "eslint src",
|
|
33
|
+
"test:type": "tsc --noEmit",
|
|
34
|
+
"test:spec": "vitest run",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
32
36
|
"prepack": "tsup"
|
|
33
37
|
},
|
|
34
38
|
"publishConfig": {
|