@pdg/react-hook 1.0.5 → 1.0.7
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 -1
- package/dist/index.esm.js +8 -27
- package/dist/index.js +8 -27
- package/package.json +2 -1
- package/dist/util.d.ts +0 -2
package/README.md
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useRef,useEffect,useState,useCallback,useLayoutEffect}from'react';function useFirstSkipEffect(effect, deps) {
|
|
1
|
+
import {useRef,useEffect,useState,useCallback,useLayoutEffect}from'react';import {equal}from'@pdg/util';function useFirstSkipEffect(effect, deps) {
|
|
2
2
|
var firstRef = useRef(true);
|
|
3
3
|
useEffect(function () {
|
|
4
4
|
if (firstRef.current) {
|
|
@@ -8,26 +8,7 @@ import {useRef,useEffect,useState,useCallback,useLayoutEffect}from'react';functi
|
|
|
8
8
|
effect();
|
|
9
9
|
}
|
|
10
10
|
}, deps);
|
|
11
|
-
}
|
|
12
|
-
if (v1 === v2)
|
|
13
|
-
return true;
|
|
14
|
-
if (typeof v1 !== typeof v2)
|
|
15
|
-
return false;
|
|
16
|
-
if (v1 == null || v2 == null)
|
|
17
|
-
return false;
|
|
18
|
-
if (Array.isArray(v1) && Array.isArray(v2)) {
|
|
19
|
-
if (v1.length !== v2.length)
|
|
20
|
-
return false;
|
|
21
|
-
for (var i = 0; i < v1.length; i += 1) {
|
|
22
|
-
if (v1[i] !== v2[i])
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return v1 === v2;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};function useAutoUpdateState(p1, p2) {
|
|
11
|
+
}function useAutoUpdateState(p1, p2) {
|
|
31
12
|
var state = typeof p1 === 'function' ? undefined : p1;
|
|
32
13
|
var finalStateCallback = typeof p1 === 'function' ? p1 : p2;
|
|
33
14
|
var _a = useState(0), setUpdateKey = _a[1];
|
|
@@ -40,21 +21,21 @@ import {useRef,useEffect,useState,useCallback,useLayoutEffect}from'react';functi
|
|
|
40
21
|
}, []);
|
|
41
22
|
useFirstSkipEffect(function () {
|
|
42
23
|
var newState = finalStateCallback ? finalStateCallback(state) : state;
|
|
43
|
-
if (!
|
|
24
|
+
if (!equal(newState, _state.current)) {
|
|
44
25
|
_state.current = newState;
|
|
45
26
|
forceUpdate();
|
|
46
27
|
}
|
|
47
28
|
}, [state]);
|
|
48
29
|
useFirstSkipEffect(function () {
|
|
49
30
|
var newState = finalStateCallback ? finalStateCallback(_state.current) : _state.current;
|
|
50
|
-
if (!
|
|
31
|
+
if (!equal(newState, _state.current)) {
|
|
51
32
|
_state.current = newState;
|
|
52
33
|
forceUpdate();
|
|
53
34
|
}
|
|
54
35
|
}, [finalStateCallback]);
|
|
55
36
|
var setState = useCallback(function (newState) {
|
|
56
37
|
var finalNewState = typeof newState === 'function' ? newState(_state.current) : newState;
|
|
57
|
-
if (!
|
|
38
|
+
if (!equal(_state.current, finalNewState)) {
|
|
58
39
|
_state.current = finalNewState;
|
|
59
40
|
forceUpdate();
|
|
60
41
|
}
|
|
@@ -83,21 +64,21 @@ import {useRef,useEffect,useState,useCallback,useLayoutEffect}from'react';functi
|
|
|
83
64
|
}, []);
|
|
84
65
|
useFirstSkipLayoutEffect(function () {
|
|
85
66
|
var newState = finalStateCallback ? finalStateCallback(state) : state;
|
|
86
|
-
if (!
|
|
67
|
+
if (!equal(newState, _state.current)) {
|
|
87
68
|
_state.current = newState;
|
|
88
69
|
forceUpdate();
|
|
89
70
|
}
|
|
90
71
|
}, [state]);
|
|
91
72
|
useFirstSkipLayoutEffect(function () {
|
|
92
73
|
var newState = finalStateCallback ? finalStateCallback(_state.current) : _state.current;
|
|
93
|
-
if (!
|
|
74
|
+
if (!equal(newState, _state.current)) {
|
|
94
75
|
_state.current = newState;
|
|
95
76
|
forceUpdate();
|
|
96
77
|
}
|
|
97
78
|
}, [finalStateCallback]);
|
|
98
79
|
var setState = useCallback(function (newState) {
|
|
99
80
|
var finalNewState = typeof newState === 'function' ? newState(_state.current) : newState;
|
|
100
|
-
if (!
|
|
81
|
+
if (!equal(_state.current, finalNewState)) {
|
|
101
82
|
_state.current = finalNewState;
|
|
102
83
|
forceUpdate();
|
|
103
84
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var react=require('react');function useFirstSkipEffect(effect, deps) {
|
|
1
|
+
'use strict';var react=require('react'),util=require('@pdg/util');function useFirstSkipEffect(effect, deps) {
|
|
2
2
|
var firstRef = react.useRef(true);
|
|
3
3
|
react.useEffect(function () {
|
|
4
4
|
if (firstRef.current) {
|
|
@@ -8,26 +8,7 @@
|
|
|
8
8
|
effect();
|
|
9
9
|
}
|
|
10
10
|
}, deps);
|
|
11
|
-
}
|
|
12
|
-
if (v1 === v2)
|
|
13
|
-
return true;
|
|
14
|
-
if (typeof v1 !== typeof v2)
|
|
15
|
-
return false;
|
|
16
|
-
if (v1 == null || v2 == null)
|
|
17
|
-
return false;
|
|
18
|
-
if (Array.isArray(v1) && Array.isArray(v2)) {
|
|
19
|
-
if (v1.length !== v2.length)
|
|
20
|
-
return false;
|
|
21
|
-
for (var i = 0; i < v1.length; i += 1) {
|
|
22
|
-
if (v1[i] !== v2[i])
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return v1 === v2;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};function useAutoUpdateState(p1, p2) {
|
|
11
|
+
}function useAutoUpdateState(p1, p2) {
|
|
31
12
|
var state = typeof p1 === 'function' ? undefined : p1;
|
|
32
13
|
var finalStateCallback = typeof p1 === 'function' ? p1 : p2;
|
|
33
14
|
var _a = react.useState(0), setUpdateKey = _a[1];
|
|
@@ -40,21 +21,21 @@
|
|
|
40
21
|
}, []);
|
|
41
22
|
useFirstSkipEffect(function () {
|
|
42
23
|
var newState = finalStateCallback ? finalStateCallback(state) : state;
|
|
43
|
-
if (!
|
|
24
|
+
if (!util.equal(newState, _state.current)) {
|
|
44
25
|
_state.current = newState;
|
|
45
26
|
forceUpdate();
|
|
46
27
|
}
|
|
47
28
|
}, [state]);
|
|
48
29
|
useFirstSkipEffect(function () {
|
|
49
30
|
var newState = finalStateCallback ? finalStateCallback(_state.current) : _state.current;
|
|
50
|
-
if (!
|
|
31
|
+
if (!util.equal(newState, _state.current)) {
|
|
51
32
|
_state.current = newState;
|
|
52
33
|
forceUpdate();
|
|
53
34
|
}
|
|
54
35
|
}, [finalStateCallback]);
|
|
55
36
|
var setState = react.useCallback(function (newState) {
|
|
56
37
|
var finalNewState = typeof newState === 'function' ? newState(_state.current) : newState;
|
|
57
|
-
if (!
|
|
38
|
+
if (!util.equal(_state.current, finalNewState)) {
|
|
58
39
|
_state.current = finalNewState;
|
|
59
40
|
forceUpdate();
|
|
60
41
|
}
|
|
@@ -83,21 +64,21 @@
|
|
|
83
64
|
}, []);
|
|
84
65
|
useFirstSkipLayoutEffect(function () {
|
|
85
66
|
var newState = finalStateCallback ? finalStateCallback(state) : state;
|
|
86
|
-
if (!
|
|
67
|
+
if (!util.equal(newState, _state.current)) {
|
|
87
68
|
_state.current = newState;
|
|
88
69
|
forceUpdate();
|
|
89
70
|
}
|
|
90
71
|
}, [state]);
|
|
91
72
|
useFirstSkipLayoutEffect(function () {
|
|
92
73
|
var newState = finalStateCallback ? finalStateCallback(_state.current) : _state.current;
|
|
93
|
-
if (!
|
|
74
|
+
if (!util.equal(newState, _state.current)) {
|
|
94
75
|
_state.current = newState;
|
|
95
76
|
forceUpdate();
|
|
96
77
|
}
|
|
97
78
|
}, [finalStateCallback]);
|
|
98
79
|
var setState = react.useCallback(function (newState) {
|
|
99
80
|
var finalNewState = typeof newState === 'function' ? newState(_state.current) : newState;
|
|
100
|
-
if (!
|
|
81
|
+
if (!util.equal(_state.current, finalNewState)) {
|
|
101
82
|
_state.current = finalNewState;
|
|
102
83
|
forceUpdate();
|
|
103
84
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdg/react-hook",
|
|
3
3
|
"title": "React Hook",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"description": "React Hook",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"javascript"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
+
"@pdg/util": "^1.0.13",
|
|
41
42
|
"@types/react": "^17.0.0 || ^18.0.0",
|
|
42
43
|
"react": "^17.0.0 || ^18.0.0",
|
|
43
44
|
"react-dom": "^17.0.0 || ^18.0.0"
|
package/dist/util.d.ts
DELETED