@reactuses/core 2.2.1 → 2.2.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.cjs +48 -51
- package/dist/index.mjs +49 -52
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -81,6 +81,49 @@ function useEvent(fn) {
|
|
|
81
81
|
}, []);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
const isPrimitive$1 = (val) => val !== Object(val);
|
|
85
|
+
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
86
|
+
if (process.env.NODE_ENV !== "production") {
|
|
87
|
+
if (!(deps instanceof Array) || !deps.length) {
|
|
88
|
+
console.warn(
|
|
89
|
+
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (deps.every(isPrimitive$1)) {
|
|
93
|
+
console.warn(
|
|
94
|
+
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (typeof depsEqual !== "function") {
|
|
98
|
+
console.warn(
|
|
99
|
+
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const ref = React.useRef(void 0);
|
|
104
|
+
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
105
|
+
ref.current = deps;
|
|
106
|
+
}
|
|
107
|
+
React.useEffect(effect, ref.current);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const isPrimitive = (val) => val !== Object(val);
|
|
111
|
+
function useDeepCompareEffect(effect, deps) {
|
|
112
|
+
if (process.env.NODE_ENV !== "production") {
|
|
113
|
+
if (!(deps instanceof Array) || !deps.length) {
|
|
114
|
+
console.warn(
|
|
115
|
+
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (deps.every(isPrimitive)) {
|
|
119
|
+
console.warn(
|
|
120
|
+
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
useCustomCompareEffect(effect, deps, lodash.isEqual);
|
|
125
|
+
}
|
|
126
|
+
|
|
84
127
|
const StorageSerializers = {
|
|
85
128
|
boolean: {
|
|
86
129
|
read: (v) => v === "true",
|
|
@@ -127,15 +170,12 @@ function useStorage(key, defaults, getStorage, options = {}) {
|
|
|
127
170
|
onError(err);
|
|
128
171
|
}
|
|
129
172
|
const type = guessSerializerType(defaults);
|
|
130
|
-
const serializer = React.useMemo(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
},
|
|
135
|
-
[options.serializer, type]
|
|
136
|
-
);
|
|
173
|
+
const serializer = React.useMemo(() => {
|
|
174
|
+
var _a;
|
|
175
|
+
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
176
|
+
}, [options.serializer, type]);
|
|
137
177
|
const [state, setState] = React.useState(defaults);
|
|
138
|
-
|
|
178
|
+
useDeepCompareEffect(() => {
|
|
139
179
|
const getStoredValue = () => {
|
|
140
180
|
try {
|
|
141
181
|
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
@@ -514,49 +554,6 @@ function useLatestElement(target, defaultElement) {
|
|
|
514
554
|
return ref;
|
|
515
555
|
}
|
|
516
556
|
|
|
517
|
-
const isPrimitive$1 = (val) => val !== Object(val);
|
|
518
|
-
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
519
|
-
if (process.env.NODE_ENV !== "production") {
|
|
520
|
-
if (!(deps instanceof Array) || !deps.length) {
|
|
521
|
-
console.warn(
|
|
522
|
-
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
if (deps.every(isPrimitive$1)) {
|
|
526
|
-
console.warn(
|
|
527
|
-
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
if (typeof depsEqual !== "function") {
|
|
531
|
-
console.warn(
|
|
532
|
-
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
const ref = React.useRef(void 0);
|
|
537
|
-
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
538
|
-
ref.current = deps;
|
|
539
|
-
}
|
|
540
|
-
React.useEffect(effect, ref.current);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const isPrimitive = (val) => val !== Object(val);
|
|
544
|
-
function useDeepCompareEffect(effect, deps) {
|
|
545
|
-
if (process.env.NODE_ENV !== "production") {
|
|
546
|
-
if (!(deps instanceof Array) || !deps.length) {
|
|
547
|
-
console.warn(
|
|
548
|
-
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
if (deps.every(isPrimitive)) {
|
|
552
|
-
console.warn(
|
|
553
|
-
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
useCustomCompareEffect(effect, deps, lodash.isEqual);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
557
|
function useEventListener(eventName, handler, element, options) {
|
|
561
558
|
const savedHandler = useLatest(handler);
|
|
562
559
|
const targetElementRef = useLatestElement(element, defaultWindow);
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useRef, useEffect, useLayoutEffect, useCallback, useMemo, useState, useReducer } from 'react';
|
|
2
|
-
import { throttle, debounce
|
|
2
|
+
import { isEqual, throttle, debounce } from 'lodash';
|
|
3
3
|
|
|
4
4
|
function usePrevious(state) {
|
|
5
5
|
const ref = useRef();
|
|
@@ -73,6 +73,49 @@ function useEvent(fn) {
|
|
|
73
73
|
}, []);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
const isPrimitive$1 = (val) => val !== Object(val);
|
|
77
|
+
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
78
|
+
if (process.env.NODE_ENV !== "production") {
|
|
79
|
+
if (!(deps instanceof Array) || !deps.length) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (deps.every(isPrimitive$1)) {
|
|
85
|
+
console.warn(
|
|
86
|
+
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (typeof depsEqual !== "function") {
|
|
90
|
+
console.warn(
|
|
91
|
+
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const ref = useRef(void 0);
|
|
96
|
+
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
97
|
+
ref.current = deps;
|
|
98
|
+
}
|
|
99
|
+
useEffect(effect, ref.current);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const isPrimitive = (val) => val !== Object(val);
|
|
103
|
+
function useDeepCompareEffect(effect, deps) {
|
|
104
|
+
if (process.env.NODE_ENV !== "production") {
|
|
105
|
+
if (!(deps instanceof Array) || !deps.length) {
|
|
106
|
+
console.warn(
|
|
107
|
+
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (deps.every(isPrimitive)) {
|
|
111
|
+
console.warn(
|
|
112
|
+
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
useCustomCompareEffect(effect, deps, isEqual);
|
|
117
|
+
}
|
|
118
|
+
|
|
76
119
|
const StorageSerializers = {
|
|
77
120
|
boolean: {
|
|
78
121
|
read: (v) => v === "true",
|
|
@@ -119,15 +162,12 @@ function useStorage(key, defaults, getStorage, options = {}) {
|
|
|
119
162
|
onError(err);
|
|
120
163
|
}
|
|
121
164
|
const type = guessSerializerType(defaults);
|
|
122
|
-
const serializer = useMemo(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
},
|
|
127
|
-
[options.serializer, type]
|
|
128
|
-
);
|
|
165
|
+
const serializer = useMemo(() => {
|
|
166
|
+
var _a;
|
|
167
|
+
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
168
|
+
}, [options.serializer, type]);
|
|
129
169
|
const [state, setState] = useState(defaults);
|
|
130
|
-
|
|
170
|
+
useDeepCompareEffect(() => {
|
|
131
171
|
const getStoredValue = () => {
|
|
132
172
|
try {
|
|
133
173
|
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
@@ -506,49 +546,6 @@ function useLatestElement(target, defaultElement) {
|
|
|
506
546
|
return ref;
|
|
507
547
|
}
|
|
508
548
|
|
|
509
|
-
const isPrimitive$1 = (val) => val !== Object(val);
|
|
510
|
-
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
511
|
-
if (process.env.NODE_ENV !== "production") {
|
|
512
|
-
if (!(deps instanceof Array) || !deps.length) {
|
|
513
|
-
console.warn(
|
|
514
|
-
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
if (deps.every(isPrimitive$1)) {
|
|
518
|
-
console.warn(
|
|
519
|
-
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
if (typeof depsEqual !== "function") {
|
|
523
|
-
console.warn(
|
|
524
|
-
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
const ref = useRef(void 0);
|
|
529
|
-
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
530
|
-
ref.current = deps;
|
|
531
|
-
}
|
|
532
|
-
useEffect(effect, ref.current);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const isPrimitive = (val) => val !== Object(val);
|
|
536
|
-
function useDeepCompareEffect(effect, deps) {
|
|
537
|
-
if (process.env.NODE_ENV !== "production") {
|
|
538
|
-
if (!(deps instanceof Array) || !deps.length) {
|
|
539
|
-
console.warn(
|
|
540
|
-
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
if (deps.every(isPrimitive)) {
|
|
544
|
-
console.warn(
|
|
545
|
-
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
useCustomCompareEffect(effect, deps, isEqual);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
549
|
function useEventListener(eventName, handler, element, options) {
|
|
553
550
|
const savedHandler = useLatest(handler);
|
|
554
551
|
const targetElementRef = useLatestElement(element, defaultWindow);
|