@pdg/react-hook 2.0.3 → 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 -53
- package/dist/index.js +58 -68
- package/package.json +3 -2
- package/dist/change/index.d.ts +0 -1
- package/dist/change/useChange.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,57 +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, t0) {
|
|
46
|
-
var skipFirst = t0 === undefined ? false : t0;
|
|
47
|
-
var _React$useState = React.useState(skipFirst ? false : "|||||skip|||||first|||||"),
|
|
48
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
49
|
-
_value = _React$useState2[0],
|
|
50
|
-
_setValue = _React$useState2[1];
|
|
51
|
-
if (value !== _value) {
|
|
52
|
-
_setValue(value);
|
|
53
|
-
callback();
|
|
54
|
-
}
|
|
55
|
-
}function useMountedRef(t0) {
|
|
56
|
-
var $ = c(2);
|
|
57
|
-
var initialValue = t0 === undefined ? true : t0;
|
|
58
|
-
var isMountedRef = useRef(initialValue);
|
|
59
|
-
var t1;
|
|
60
|
-
var t2;
|
|
61
|
-
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
62
|
-
t1 = function t1() {
|
|
63
|
-
isMountedRef.current = true;
|
|
64
|
-
return function () {
|
|
65
|
-
isMountedRef.current = false;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
t2 = [];
|
|
69
|
-
$[0] = t1;
|
|
70
|
-
$[1] = t2;
|
|
71
|
-
} else {
|
|
72
|
-
t1 = $[0];
|
|
73
|
-
t2 = $[1];
|
|
74
|
-
}
|
|
75
|
-
useEffect(t1, t2);
|
|
76
|
-
return isMountedRef;
|
|
77
|
-
}function useAutoUpdateRef(value) {
|
|
78
|
-
var $ = c(3);
|
|
79
|
-
var valueRef = useRef(value);
|
|
80
|
-
var t0;
|
|
81
|
-
var t1;
|
|
82
|
-
if ($[0] !== value) {
|
|
83
|
-
t0 = function t0() {
|
|
84
|
-
valueRef.current = value;
|
|
85
|
-
};
|
|
86
|
-
t1 = [value];
|
|
87
|
-
$[0] = value;
|
|
88
|
-
$[1] = t0;
|
|
89
|
-
$[2] = t1;
|
|
90
|
-
} else {
|
|
91
|
-
t0 = $[1];
|
|
92
|
-
t1 = $[2];
|
|
93
|
-
}
|
|
94
|
-
useLayoutEffect(t0, t1);
|
|
95
|
-
return valueRef;
|
|
96
86
|
}// state 값을 Function 으로 지정한 경우 (사용 불가)
|
|
97
87
|
|
|
98
88
|
// state 값만 받는 경우 (state 에 function 지정 불가)
|
|
@@ -480,4 +470,4 @@ function useAutoUpdateState(state, callback) {
|
|
|
480
470
|
t3 = $[7];
|
|
481
471
|
}
|
|
482
472
|
useEffect(t2, t3);
|
|
483
|
-
}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,57 +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, t0) {
|
|
46
|
-
var skipFirst = t0 === undefined ? false : t0;
|
|
47
|
-
var _React$useState = React.useState(skipFirst ? false : "|||||skip|||||first|||||"),
|
|
48
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
49
|
-
_value = _React$useState2[0],
|
|
50
|
-
_setValue = _React$useState2[1];
|
|
51
|
-
if (value !== _value) {
|
|
52
|
-
_setValue(value);
|
|
53
|
-
callback();
|
|
54
|
-
}
|
|
55
|
-
}function useMountedRef(t0) {
|
|
56
|
-
var $ = compilerRuntime.c(2);
|
|
57
|
-
var initialValue = t0 === undefined ? true : t0;
|
|
58
|
-
var isMountedRef = React.useRef(initialValue);
|
|
59
|
-
var t1;
|
|
60
|
-
var t2;
|
|
61
|
-
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
62
|
-
t1 = function t1() {
|
|
63
|
-
isMountedRef.current = true;
|
|
64
|
-
return function () {
|
|
65
|
-
isMountedRef.current = false;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
t2 = [];
|
|
69
|
-
$[0] = t1;
|
|
70
|
-
$[1] = t2;
|
|
71
|
-
} else {
|
|
72
|
-
t1 = $[0];
|
|
73
|
-
t2 = $[1];
|
|
74
|
-
}
|
|
75
|
-
React.useEffect(t1, t2);
|
|
76
|
-
return isMountedRef;
|
|
77
|
-
}function useAutoUpdateRef(value) {
|
|
78
|
-
var $ = compilerRuntime.c(3);
|
|
79
|
-
var valueRef = React.useRef(value);
|
|
80
|
-
var t0;
|
|
81
|
-
var t1;
|
|
82
|
-
if ($[0] !== value) {
|
|
83
|
-
t0 = function t0() {
|
|
84
|
-
valueRef.current = value;
|
|
85
|
-
};
|
|
86
|
-
t1 = [value];
|
|
87
|
-
$[0] = value;
|
|
88
|
-
$[1] = t0;
|
|
89
|
-
$[2] = t1;
|
|
90
|
-
} else {
|
|
91
|
-
t0 = $[1];
|
|
92
|
-
t1 = $[2];
|
|
93
|
-
}
|
|
94
|
-
React.useLayoutEffect(t0, t1);
|
|
95
|
-
return valueRef;
|
|
96
86
|
}// state 값을 Function 으로 지정한 경우 (사용 불가)
|
|
97
87
|
|
|
98
88
|
// state 값만 받는 경우 (state 에 function 지정 불가)
|
|
@@ -116,7 +106,7 @@ function useAutoUpdateRefState(state, callback) {
|
|
|
116
106
|
} else {
|
|
117
107
|
t0 = $[2];
|
|
118
108
|
}
|
|
119
|
-
var _useState =
|
|
109
|
+
var _useState = react.useState(t0),
|
|
120
110
|
_useState2 = _slicedToArray(_useState, 2),
|
|
121
111
|
prevProps = _useState2[0],
|
|
122
112
|
setPrevProps = _useState2[1];
|
|
@@ -131,7 +121,7 @@ function useAutoUpdateRefState(state, callback) {
|
|
|
131
121
|
} else {
|
|
132
122
|
t1 = $[5];
|
|
133
123
|
}
|
|
134
|
-
var _useState3 =
|
|
124
|
+
var _useState3 = react.useState(t1),
|
|
135
125
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
136
126
|
_value = _useState4[0],
|
|
137
127
|
_setValue = _useState4[1];
|
|
@@ -205,7 +195,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
205
195
|
} else {
|
|
206
196
|
t0 = $[2];
|
|
207
197
|
}
|
|
208
|
-
var _useState =
|
|
198
|
+
var _useState = react.useState(t0),
|
|
209
199
|
_useState2 = _slicedToArray(_useState, 2),
|
|
210
200
|
prevProps = _useState2[0],
|
|
211
201
|
setPrevProps = _useState2[1];
|
|
@@ -220,7 +210,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
220
210
|
} else {
|
|
221
211
|
t1 = $[5];
|
|
222
212
|
}
|
|
223
|
-
var _useState3 =
|
|
213
|
+
var _useState3 = react.useState(t1),
|
|
224
214
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
225
215
|
_value = _useState4[0],
|
|
226
216
|
_setValue = _useState4[1];
|
|
@@ -272,11 +262,11 @@ function useAutoUpdateState(state, callback) {
|
|
|
272
262
|
return t3;
|
|
273
263
|
}function useRefState(initialState) {
|
|
274
264
|
var $ = compilerRuntime.c(3);
|
|
275
|
-
var _useState =
|
|
265
|
+
var _useState = react.useState(initialState),
|
|
276
266
|
_useState2 = _slicedToArray(_useState, 2),
|
|
277
267
|
_value = _useState2[0],
|
|
278
268
|
_setValue = _useState2[1];
|
|
279
|
-
var valueRef =
|
|
269
|
+
var valueRef = react.useRef(_value);
|
|
280
270
|
var t0;
|
|
281
271
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
282
272
|
t0 = function t0(value) {
|
|
@@ -302,8 +292,8 @@ function useAutoUpdateState(state, callback) {
|
|
|
302
292
|
return t1;
|
|
303
293
|
}function useSafeState(initialState) {
|
|
304
294
|
var $ = compilerRuntime.c(5);
|
|
305
|
-
var mountedRef =
|
|
306
|
-
var _useState =
|
|
295
|
+
var mountedRef = react.useRef(false);
|
|
296
|
+
var _useState = react.useState(initialState),
|
|
307
297
|
_useState2 = _slicedToArray(_useState, 2),
|
|
308
298
|
value = _useState2[0],
|
|
309
299
|
setValue = _useState2[1];
|
|
@@ -323,7 +313,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
323
313
|
t0 = $[0];
|
|
324
314
|
t1 = $[1];
|
|
325
315
|
}
|
|
326
|
-
|
|
316
|
+
react.useEffect(t0, t1);
|
|
327
317
|
var t2;
|
|
328
318
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
329
319
|
t2 = function t2(newValue) {
|
|
@@ -357,7 +347,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
357
347
|
}
|
|
358
348
|
}function useIntervalRef() {
|
|
359
349
|
var $ = compilerRuntime.c(3);
|
|
360
|
-
var ref =
|
|
350
|
+
var ref = react.useRef(undefined);
|
|
361
351
|
var t0;
|
|
362
352
|
var t1;
|
|
363
353
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
@@ -373,7 +363,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
373
363
|
t0 = $[0];
|
|
374
364
|
t1 = $[1];
|
|
375
365
|
}
|
|
376
|
-
|
|
366
|
+
react.useEffect(t0, t1);
|
|
377
367
|
var t2;
|
|
378
368
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
379
369
|
var setIntervalFunc = function setIntervalFunc(callback, ms) {
|
|
@@ -390,7 +380,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
390
380
|
return t2;
|
|
391
381
|
}function useTimeoutRef() {
|
|
392
382
|
var $ = compilerRuntime.c(3);
|
|
393
|
-
var ref =
|
|
383
|
+
var ref = react.useRef(undefined);
|
|
394
384
|
var t0;
|
|
395
385
|
var t1;
|
|
396
386
|
if ($[0] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
@@ -406,7 +396,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
406
396
|
t0 = $[0];
|
|
407
397
|
t1 = $[1];
|
|
408
398
|
}
|
|
409
|
-
|
|
399
|
+
react.useEffect(t0, t1);
|
|
410
400
|
var t2;
|
|
411
401
|
if ($[2] === Symbol["for"]("react.memo_cache_sentinel")) {
|
|
412
402
|
var setTimeoutFunc = function setTimeoutFunc(callback, ms) {
|
|
@@ -456,7 +446,7 @@ function useAutoUpdateState(state, callback) {
|
|
|
456
446
|
t0 = $[1];
|
|
457
447
|
t1 = $[2];
|
|
458
448
|
}
|
|
459
|
-
|
|
449
|
+
react.useImperativeHandle(ref, t0, t1);
|
|
460
450
|
var t2;
|
|
461
451
|
var t3;
|
|
462
452
|
if ($[3] !== onSetRef || $[4] !== onUnsetRef || $[5] !== value) {
|
|
@@ -479,5 +469,5 @@ function useAutoUpdateState(state, callback) {
|
|
|
479
469
|
t2 = $[6];
|
|
480
470
|
t3 = $[7];
|
|
481
471
|
}
|
|
482
|
-
|
|
483
|
-
}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 * from './useChange';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useChange(value: any, callback: () => void, skipFirst?: boolean): void;
|