@pdg/react-hook 2.0.4 → 2.0.5
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.d.ts +0 -1
- package/dist/index.esm.js +43 -61
- package/dist/index.js +58 -76
- package/package.json +3 -2
- package/dist/change/index.d.ts +0 -2
- package/dist/change/useChange.d.ts +0 -1
- package/dist/change/useFirstSkipChange.d.ts +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {c}from'react/compiler-runtime';import {useRef,useEffect,useLayoutEffect,useState,useImperativeHandle}from'react';function useMountedRef(t0) {
|
|
2
|
+
var $ = c(2);
|
|
3
|
+
var initialValue = t0 === undefined ? true : t0;
|
|
4
|
+
var isMountedRef = useRef(initialValue);
|
|
5
|
+
var t1;
|
|
6
|
+
var t2;
|
|
7
|
+
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
8
|
+
t1 = function t1() {
|
|
9
|
+
isMountedRef.current = true;
|
|
10
|
+
return function () {
|
|
11
|
+
isMountedRef.current = false;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
t2 = [];
|
|
15
|
+
$[0] = t1;
|
|
16
|
+
$[1] = t2;
|
|
17
|
+
} else {
|
|
18
|
+
t1 = $[0];
|
|
19
|
+
t2 = $[1];
|
|
20
|
+
}
|
|
21
|
+
useEffect(t1, t2);
|
|
22
|
+
return isMountedRef;
|
|
23
|
+
}function useAutoUpdateRef(value) {
|
|
24
|
+
var $ = c(3);
|
|
25
|
+
var valueRef = useRef(value);
|
|
26
|
+
var t0;
|
|
27
|
+
var t1;
|
|
28
|
+
if ($[0] !== value) {
|
|
29
|
+
t0 = function t0() {
|
|
30
|
+
valueRef.current = value;
|
|
31
|
+
};
|
|
32
|
+
t1 = [value];
|
|
33
|
+
$[0] = value;
|
|
34
|
+
$[1] = t0;
|
|
35
|
+
$[2] = t1;
|
|
36
|
+
} else {
|
|
37
|
+
t0 = $[1];
|
|
38
|
+
t1 = $[2];
|
|
39
|
+
}
|
|
40
|
+
useLayoutEffect(t0, t1);
|
|
41
|
+
return valueRef;
|
|
42
|
+
}function _arrayLikeToArray(r, a) {
|
|
2
43
|
(null == a || a > r.length) && (a = r.length);
|
|
3
44
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4
45
|
return n;
|
|
@@ -42,65 +83,6 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
42
83
|
var t = {}.toString.call(r).slice(8, -1);
|
|
43
84
|
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
44
85
|
}
|
|
45
|
-
}function useChange(value, callback) {
|
|
46
|
-
var _React$useState = React.useState(value === undefined ? null : undefined),
|
|
47
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
48
|
-
_value = _React$useState2[0],
|
|
49
|
-
_setValue = _React$useState2[1];
|
|
50
|
-
if (value !== _value) {
|
|
51
|
-
_setValue(value);
|
|
52
|
-
callback(value);
|
|
53
|
-
}
|
|
54
|
-
}function useFirstSkipChange(value, callback) {
|
|
55
|
-
var _React$useState = React.useState(value),
|
|
56
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
57
|
-
_value = _React$useState2[0],
|
|
58
|
-
_setValue = _React$useState2[1];
|
|
59
|
-
if (value !== _value) {
|
|
60
|
-
_setValue(value);
|
|
61
|
-
callback(value);
|
|
62
|
-
}
|
|
63
|
-
}function useMountedRef(t0) {
|
|
64
|
-
var $ = c(2);
|
|
65
|
-
var initialValue = t0 === undefined ? true : t0;
|
|
66
|
-
var isMountedRef = useRef(initialValue);
|
|
67
|
-
var t1;
|
|
68
|
-
var t2;
|
|
69
|
-
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
70
|
-
t1 = function t1() {
|
|
71
|
-
isMountedRef.current = true;
|
|
72
|
-
return function () {
|
|
73
|
-
isMountedRef.current = false;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
t2 = [];
|
|
77
|
-
$[0] = t1;
|
|
78
|
-
$[1] = t2;
|
|
79
|
-
} else {
|
|
80
|
-
t1 = $[0];
|
|
81
|
-
t2 = $[1];
|
|
82
|
-
}
|
|
83
|
-
useEffect(t1, t2);
|
|
84
|
-
return isMountedRef;
|
|
85
|
-
}function useAutoUpdateRef(value) {
|
|
86
|
-
var $ = c(3);
|
|
87
|
-
var valueRef = useRef(value);
|
|
88
|
-
var t0;
|
|
89
|
-
var t1;
|
|
90
|
-
if ($[0] !== value) {
|
|
91
|
-
t0 = function t0() {
|
|
92
|
-
valueRef.current = value;
|
|
93
|
-
};
|
|
94
|
-
t1 = [value];
|
|
95
|
-
$[0] = value;
|
|
96
|
-
$[1] = t0;
|
|
97
|
-
$[2] = t1;
|
|
98
|
-
} else {
|
|
99
|
-
t0 = $[1];
|
|
100
|
-
t1 = $[2];
|
|
101
|
-
}
|
|
102
|
-
useLayoutEffect(t0, t1);
|
|
103
|
-
return valueRef;
|
|
104
86
|
}// state 값을 Function 으로 지정한 경우 (사용 불가)
|
|
105
87
|
|
|
106
88
|
// state 값만 받는 경우 (state 에 function 지정 불가)
|
|
@@ -488,4 +470,4 @@ function useAutoUpdateState(state, callback) {
|
|
|
488
470
|
t3 = $[7];
|
|
489
471
|
}
|
|
490
472
|
useEffect(t2, t3);
|
|
491
|
-
}export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useAutoUpdateRefState,useAutoUpdateState,
|
|
473
|
+
}export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useAutoUpdateRefState,useAutoUpdateState,useForwardRef,useIntervalRef,useMountedRef,useRefState,useSafeState,useSafeUpdate,useTimeoutRef};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var compilerRuntime=require('react/compiler-runtime'),react=require('react');function useMountedRef(t0) {
|
|
2
|
+
var $ = compilerRuntime.c(2);
|
|
3
|
+
var initialValue = t0 === undefined ? true : t0;
|
|
4
|
+
var isMountedRef = react.useRef(initialValue);
|
|
5
|
+
var t1;
|
|
6
|
+
var t2;
|
|
7
|
+
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
8
|
+
t1 = function t1() {
|
|
9
|
+
isMountedRef.current = true;
|
|
10
|
+
return function () {
|
|
11
|
+
isMountedRef.current = false;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
t2 = [];
|
|
15
|
+
$[0] = t1;
|
|
16
|
+
$[1] = t2;
|
|
17
|
+
} else {
|
|
18
|
+
t1 = $[0];
|
|
19
|
+
t2 = $[1];
|
|
20
|
+
}
|
|
21
|
+
react.useEffect(t1, t2);
|
|
22
|
+
return isMountedRef;
|
|
23
|
+
}function useAutoUpdateRef(value) {
|
|
24
|
+
var $ = compilerRuntime.c(3);
|
|
25
|
+
var valueRef = react.useRef(value);
|
|
26
|
+
var t0;
|
|
27
|
+
var t1;
|
|
28
|
+
if ($[0] !== value) {
|
|
29
|
+
t0 = function t0() {
|
|
30
|
+
valueRef.current = value;
|
|
31
|
+
};
|
|
32
|
+
t1 = [value];
|
|
33
|
+
$[0] = value;
|
|
34
|
+
$[1] = t0;
|
|
35
|
+
$[2] = t1;
|
|
36
|
+
} else {
|
|
37
|
+
t0 = $[1];
|
|
38
|
+
t1 = $[2];
|
|
39
|
+
}
|
|
40
|
+
react.useLayoutEffect(t0, t1);
|
|
41
|
+
return valueRef;
|
|
42
|
+
}function _arrayLikeToArray(r, a) {
|
|
2
43
|
(null == a || a > r.length) && (a = r.length);
|
|
3
44
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4
45
|
return n;
|
|
@@ -42,65 +83,6 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
42
83
|
var t = {}.toString.call(r).slice(8, -1);
|
|
43
84
|
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
44
85
|
}
|
|
45
|
-
}function useChange(value, callback) {
|
|
46
|
-
var _React$useState = React.useState(value === undefined ? null : undefined),
|
|
47
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
48
|
-
_value = _React$useState2[0],
|
|
49
|
-
_setValue = _React$useState2[1];
|
|
50
|
-
if (value !== _value) {
|
|
51
|
-
_setValue(value);
|
|
52
|
-
callback(value);
|
|
53
|
-
}
|
|
54
|
-
}function useFirstSkipChange(value, callback) {
|
|
55
|
-
var _React$useState = React.useState(value),
|
|
56
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
57
|
-
_value = _React$useState2[0],
|
|
58
|
-
_setValue = _React$useState2[1];
|
|
59
|
-
if (value !== _value) {
|
|
60
|
-
_setValue(value);
|
|
61
|
-
callback(value);
|
|
62
|
-
}
|
|
63
|
-
}function useMountedRef(t0) {
|
|
64
|
-
var $ = compilerRuntime.c(2);
|
|
65
|
-
var initialValue = t0 === undefined ? true : t0;
|
|
66
|
-
var isMountedRef = React.useRef(initialValue);
|
|
67
|
-
var t1;
|
|
68
|
-
var t2;
|
|
69
|
-
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
70
|
-
t1 = function t1() {
|
|
71
|
-
isMountedRef.current = true;
|
|
72
|
-
return function () {
|
|
73
|
-
isMountedRef.current = false;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
t2 = [];
|
|
77
|
-
$[0] = t1;
|
|
78
|
-
$[1] = t2;
|
|
79
|
-
} else {
|
|
80
|
-
t1 = $[0];
|
|
81
|
-
t2 = $[1];
|
|
82
|
-
}
|
|
83
|
-
React.useEffect(t1, t2);
|
|
84
|
-
return isMountedRef;
|
|
85
|
-
}function useAutoUpdateRef(value) {
|
|
86
|
-
var $ = compilerRuntime.c(3);
|
|
87
|
-
var valueRef = React.useRef(value);
|
|
88
|
-
var t0;
|
|
89
|
-
var t1;
|
|
90
|
-
if ($[0] !== value) {
|
|
91
|
-
t0 = function t0() {
|
|
92
|
-
valueRef.current = value;
|
|
93
|
-
};
|
|
94
|
-
t1 = [value];
|
|
95
|
-
$[0] = value;
|
|
96
|
-
$[1] = t0;
|
|
97
|
-
$[2] = t1;
|
|
98
|
-
} else {
|
|
99
|
-
t0 = $[1];
|
|
100
|
-
t1 = $[2];
|
|
101
|
-
}
|
|
102
|
-
React.useLayoutEffect(t0, t1);
|
|
103
|
-
return valueRef;
|
|
104
86
|
}// state 값을 Function 으로 지정한 경우 (사용 불가)
|
|
105
87
|
|
|
106
88
|
// state 값만 받는 경우 (state 에 function 지정 불가)
|
|
@@ -124,7 +106,7 @@ function useAutoUpdateRefState(state, callback) {
|
|
|
124
106
|
} else {
|
|
125
107
|
t0 = $[2];
|
|
126
108
|
}
|
|
127
|
-
var _useState =
|
|
109
|
+
var _useState = react.useState(t0),
|
|
128
110
|
_useState2 = _slicedToArray(_useState, 2),
|
|
129
111
|
prevProps = _useState2[0],
|
|
130
112
|
setPrevProps = _useState2[1];
|
|
@@ -139,7 +121,7 @@ function useAutoUpdateRefState(state, callback) {
|
|
|
139
121
|
} else {
|
|
140
122
|
t1 = $[5];
|
|
141
123
|
}
|
|
142
|
-
var _useState3 =
|
|
124
|
+
var _useState3 = react.useState(t1),
|
|
143
125
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
144
126
|
_value = _useState4[0],
|
|
145
127
|
_setValue = _useState4[1];
|
|
@@ -213,7 +195,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
213
195
|
} else {
|
|
214
196
|
t0 = $[2];
|
|
215
197
|
}
|
|
216
|
-
var _useState =
|
|
198
|
+
var _useState = react.useState(t0),
|
|
217
199
|
_useState2 = _slicedToArray(_useState, 2),
|
|
218
200
|
prevProps = _useState2[0],
|
|
219
201
|
setPrevProps = _useState2[1];
|
|
@@ -228,7 +210,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
228
210
|
} else {
|
|
229
211
|
t1 = $[5];
|
|
230
212
|
}
|
|
231
|
-
var _useState3 =
|
|
213
|
+
var _useState3 = react.useState(t1),
|
|
232
214
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
233
215
|
_value = _useState4[0],
|
|
234
216
|
_setValue = _useState4[1];
|
|
@@ -280,11 +262,11 @@ function useAutoUpdateState(state, callback) {
|
|
|
280
262
|
return t3;
|
|
281
263
|
}function useRefState(initialState) {
|
|
282
264
|
var $ = compilerRuntime.c(3);
|
|
283
|
-
var _useState =
|
|
265
|
+
var _useState = react.useState(initialState),
|
|
284
266
|
_useState2 = _slicedToArray(_useState, 2),
|
|
285
267
|
_value = _useState2[0],
|
|
286
268
|
_setValue = _useState2[1];
|
|
287
|
-
var valueRef =
|
|
269
|
+
var valueRef = react.useRef(_value);
|
|
288
270
|
var t0;
|
|
289
271
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
290
272
|
t0 = function t0(value) {
|
|
@@ -310,8 +292,8 @@ function useAutoUpdateState(state, callback) {
|
|
|
310
292
|
return t1;
|
|
311
293
|
}function useSafeState(initialState) {
|
|
312
294
|
var $ = compilerRuntime.c(5);
|
|
313
|
-
var mountedRef =
|
|
314
|
-
var _useState =
|
|
295
|
+
var mountedRef = react.useRef(false);
|
|
296
|
+
var _useState = react.useState(initialState),
|
|
315
297
|
_useState2 = _slicedToArray(_useState, 2),
|
|
316
298
|
value = _useState2[0],
|
|
317
299
|
setValue = _useState2[1];
|
|
@@ -331,7 +313,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
331
313
|
t0 = $[0];
|
|
332
314
|
t1 = $[1];
|
|
333
315
|
}
|
|
334
|
-
|
|
316
|
+
react.useEffect(t0, t1);
|
|
335
317
|
var t2;
|
|
336
318
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
337
319
|
t2 = function t2(newValue) {
|
|
@@ -365,7 +347,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
365
347
|
}
|
|
366
348
|
}function useIntervalRef() {
|
|
367
349
|
var $ = compilerRuntime.c(3);
|
|
368
|
-
var ref =
|
|
350
|
+
var ref = react.useRef(undefined);
|
|
369
351
|
var t0;
|
|
370
352
|
var t1;
|
|
371
353
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
@@ -381,7 +363,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
381
363
|
t0 = $[0];
|
|
382
364
|
t1 = $[1];
|
|
383
365
|
}
|
|
384
|
-
|
|
366
|
+
react.useEffect(t0, t1);
|
|
385
367
|
var t2;
|
|
386
368
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
387
369
|
var setIntervalFunc = function setIntervalFunc(callback, ms) {
|
|
@@ -398,7 +380,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
398
380
|
return t2;
|
|
399
381
|
}function useTimeoutRef() {
|
|
400
382
|
var $ = compilerRuntime.c(3);
|
|
401
|
-
var ref =
|
|
383
|
+
var ref = react.useRef(undefined);
|
|
402
384
|
var t0;
|
|
403
385
|
var t1;
|
|
404
386
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
@@ -414,7 +396,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
414
396
|
t0 = $[0];
|
|
415
397
|
t1 = $[1];
|
|
416
398
|
}
|
|
417
|
-
|
|
399
|
+
react.useEffect(t0, t1);
|
|
418
400
|
var t2;
|
|
419
401
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
420
402
|
var setTimeoutFunc = function setTimeoutFunc(callback, ms) {
|
|
@@ -464,7 +446,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
464
446
|
t0 = $[1];
|
|
465
447
|
t1 = $[2];
|
|
466
448
|
}
|
|
467
|
-
|
|
449
|
+
react.useImperativeHandle(ref, t0, t1);
|
|
468
450
|
var t2;
|
|
469
451
|
var t3;
|
|
470
452
|
if ($[3] !== onSetRef || $[4] !== onUnsetRef || $[5] !== value) {
|
|
@@ -487,5 +469,5 @@ function useAutoUpdateState(state, callback) {
|
|
|
487
469
|
t2 = $[6];
|
|
488
470
|
t3 = $[7];
|
|
489
471
|
}
|
|
490
|
-
|
|
491
|
-
}exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useAutoUpdateRefState=useAutoUpdateRefState;exports.useAutoUpdateState=useAutoUpdateState;exports.
|
|
472
|
+
react.useEffect(t2, t3);
|
|
473
|
+
}exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useAutoUpdateRefState=useAutoUpdateRefState;exports.useAutoUpdateState=useAutoUpdateState;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useMountedRef=useMountedRef;exports.useRefState=useRefState;exports.useSafeState=useSafeState;exports.useSafeUpdate=useSafeUpdate;exports.useTimeoutRef=useTimeoutRef;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pdg/react-hook",
|
|
3
3
|
"title": "Typescript React Hook Module",
|
|
4
4
|
"description": "Typescript React Hook Module",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.esm.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dev": "cd examples && npm run dev",
|
|
32
32
|
"watchman:del": "watchman watch-del \"${PWD}\" ; watchman watch-project \"${PWD}\"",
|
|
33
33
|
"build:examples": "cd examples && npm run build",
|
|
34
|
-
"build": "npm run watchman:del &&
|
|
34
|
+
"build": "npm run watchman:del && rollup -c --bundleConfigAsCjs",
|
|
35
35
|
"git:commit": "node .git-commit.cjs",
|
|
36
36
|
"git:push": "git push",
|
|
37
37
|
"git:commit:push": "npm run git:commit && npm run git:push",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@eslint/js": "9.39.1",
|
|
67
67
|
"@rollup/plugin-babel": "^6.1.0",
|
|
68
68
|
"@rollup/plugin-commonjs": "29.0.0",
|
|
69
|
+
"@rollup/plugin-eslint": "^9.2.0",
|
|
69
70
|
"@rollup/plugin-node-resolve": "16.0.3",
|
|
70
71
|
"@types/node": "^22.19.2",
|
|
71
72
|
"@types/react": "19.2.7",
|
package/dist/change/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useChange<T>(value: T, callback: (value: T) => void): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useFirstSkipChange<T>(value: T, callback: (value: T) => void): void;
|