@hanzogui/use-event 3.0.6 → 4.3.1
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/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useEvent.cjs +13 -11
- package/dist/cjs/useEvent.native.js +13 -11
- package/dist/cjs/useEvent.native.js.map +1 -1
- package/dist/cjs/useGet.cjs +29 -26
- package/dist/cjs/useGet.native.js +34 -29
- package/dist/cjs/useGet.native.js.map +1 -1
- package/dist/esm/useEvent.mjs +1 -1
- package/dist/esm/useEvent.mjs.map +1 -1
- package/dist/esm/useEvent.native.js +1 -1
- package/dist/esm/useEvent.native.js.map +1 -1
- package/dist/esm/useGet.mjs +5 -4
- package/dist/esm/useGet.mjs.map +1 -1
- package/dist/esm/useGet.native.js +9 -6
- package/dist/esm/useGet.native.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,15 +3,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
7
8
|
get: () => from[key],
|
|
8
9
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
15
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
-
value:
|
|
16
|
+
value: true
|
|
15
17
|
}), mod);
|
|
16
18
|
var index_exports = {};
|
|
17
19
|
module.exports = __toCommonJS(index_exports);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -5,15 +5,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
9
10
|
get: () => from[key],
|
|
10
11
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
17
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value:
|
|
18
|
+
value: true
|
|
17
19
|
}), mod);
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,wBADd,EAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
|
package/dist/cjs/useEvent.cjs
CHANGED
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var useEvent_exports = {};
|
|
22
24
|
__export(useEvent_exports, {
|
|
@@ -25,7 +27,7 @@ __export(useEvent_exports, {
|
|
|
25
27
|
module.exports = __toCommonJS(useEvent_exports);
|
|
26
28
|
var import_useGet = require("./useGet.cjs");
|
|
27
29
|
function useEvent(callback) {
|
|
28
|
-
return (0, import_useGet.useGet)(callback, defaultValue,
|
|
30
|
+
return (0, import_useGet.useGet)(callback, defaultValue, true);
|
|
29
31
|
}
|
|
30
32
|
const defaultValue = () => {
|
|
31
33
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var useEvent_exports = {};
|
|
24
26
|
__export(useEvent_exports, {
|
|
@@ -27,7 +29,7 @@ __export(useEvent_exports, {
|
|
|
27
29
|
module.exports = __toCommonJS(useEvent_exports);
|
|
28
30
|
var import_useGet = require("./useGet.native.js");
|
|
29
31
|
function useEvent(callback) {
|
|
30
|
-
return (0, import_useGet.useGet)(callback, defaultValue,
|
|
32
|
+
return (0, import_useGet.useGet)(callback, defaultValue, true);
|
|
31
33
|
}
|
|
32
34
|
var defaultValue = function () {
|
|
33
35
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useEvent_exports","__export","useEvent","module","exports","import_useGet","require","callback","useGet","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useEvent_exports","__export","useEvent","module","exports","import_useGet","require","callback","useGet","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAuB,CAAAK,gBAAA;AAIhB,IAAAK,aAAS,GAAgCC,OAAA,CAAiB;AAC/D,SAAAJ,QAAOA,CAAAK,QAAA;EACT,WAAAF,aAAA,CAAAG,MAAA,EAAAD,QAAA,EAAAE,YAAA;AAEA;AACE,IAAAA,YAAU,GAAM,SAAAA,CAAA;EAClB,UAAAC,KAAA","ignoreList":[]}
|
package/dist/cjs/useGet.cjs
CHANGED
|
@@ -2,44 +2,47 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var useGet_exports = {};
|
|
33
35
|
__export(useGet_exports, {
|
|
34
36
|
useGet: () => useGet
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(useGet_exports);
|
|
37
39
|
var React = __toESM(require("react"), 1);
|
|
38
|
-
const isServer = typeof window
|
|
39
|
-
|
|
40
|
+
const isServer = typeof window === "undefined";
|
|
41
|
+
const useIsomorphicInsertionEffect = isServer ? React.useEffect : React.useInsertionEffect || React.useLayoutEffect;
|
|
40
42
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
41
43
|
const curRef = React.useRef(initialValue ?? currentValue);
|
|
42
|
-
|
|
44
|
+
useIsomorphicInsertionEffect(() => {
|
|
43
45
|
curRef.current = currentValue;
|
|
44
|
-
})
|
|
46
|
+
});
|
|
47
|
+
return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
|
|
45
48
|
}
|
|
@@ -4,47 +4,52 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var useGet_exports = {};
|
|
35
37
|
__export(useGet_exports, {
|
|
36
38
|
useGet: () => useGet
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(useGet_exports);
|
|
39
|
-
var React = __toESM(require("react"), 1)
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
var isServer = typeof window === "undefined";
|
|
43
|
+
var useIsomorphicInsertionEffect = isServer ? React.useEffect : React.useInsertionEffect || React.useLayoutEffect;
|
|
42
44
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
43
|
-
var curRef = React.useRef(initialValue
|
|
44
|
-
|
|
45
|
+
var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
|
|
46
|
+
useIsomorphicInsertionEffect(function () {
|
|
45
47
|
curRef.current = currentValue;
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
+
});
|
|
49
|
+
return React.useCallback(forwardToFunction ? function () {
|
|
50
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
51
|
+
args[_key] = arguments[_key];
|
|
52
|
+
}
|
|
48
53
|
var _curRef_current;
|
|
49
54
|
return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
|
|
50
55
|
} : function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useGet_exports","__export","useGet","module","exports","React","__toESM","require","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useGet_exports","__export","useGet","module","exports","React","__toESM","require","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,cAAA;AAAAC,QAAA,CAAAD,cAAA;EAAAE,MAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAT,YAAA,CAAAK,cAAA;AAEvB,IAAAK,KAAM,GAAAC,OAAW,CAAAC,OAAO,QAAW;AAMnC,IAAAC,QAAM,UAAAC,MAAA,gBAA+B;AAM9B,IAAAC,4BAEL,GAAAF,QAAA,GACAH,KAAA,CAAAM,SAAA,GACSN,KAAA,CAAAO,kBAAA,IAAAP,KAAA,CAAAQ,eAAA;AACT,SAAMX,OAAAY,YAAe,EAAYC,YAAA,EAAAC,iBAA4B;EAC7D,IAAAC,MAAA,GAAAZ,KAAA,CAAAa,MAAA,CAAAH,YAAmC,aAAAA,YAAA,cAAAA,YAAA,GAAAD,YAAA;EACjCJ,4BAAiB;IAClBO,MAAA,CAAAE,OAAA,GAAAL,YAAA;EAED;EAAa,OACXT,KAAA,CAAAe,WACI,CAAAJ,iBAAoB,eAAS;IAEjC,KAAC,IAAAK,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MACHF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACF","ignoreList":[]}
|
package/dist/esm/useEvent.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,
|
|
1
|
+
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,MAAMA,YAAA,GAAeA,CAAA,KAAM;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useGet } from "./useGet.native.js";
|
|
2
2
|
function useEvent(callback) {
|
|
3
|
-
return useGet(callback, defaultValue,
|
|
3
|
+
return useGet(callback, defaultValue, true);
|
|
4
4
|
}
|
|
5
5
|
var defaultValue = function () {
|
|
6
6
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,
|
|
1
|
+
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,IAAAA,YAAM,YAAAA,CAAA,EAAqB;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
|
package/dist/esm/useGet.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
const isServer = typeof window
|
|
3
|
-
|
|
2
|
+
const isServer = typeof window === "undefined";
|
|
3
|
+
const useIsomorphicInsertionEffect = isServer ? React.useEffect : React.useInsertionEffect || React.useLayoutEffect;
|
|
4
4
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
5
5
|
const curRef = React.useRef(initialValue ?? currentValue);
|
|
6
|
-
|
|
6
|
+
useIsomorphicInsertionEffect(() => {
|
|
7
7
|
curRef.current = currentValue;
|
|
8
|
-
})
|
|
8
|
+
});
|
|
9
|
+
return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
|
|
9
10
|
}
|
|
10
11
|
export { useGet };
|
|
11
12
|
//# sourceMappingURL=useGet.mjs.map
|
package/dist/esm/useGet.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","args","apply"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,MAAMC,QAAA,GAAW,OAAOC,MAAA,
|
|
1
|
+
{"version":3,"names":["React","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","args","apply"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,MAAMC,QAAA,GAAW,OAAOC,MAAA,KAAW;AAMnC,MAAMC,4BAAA,GAA+BF,QAAA,GACjCD,KAAA,CAAMI,SAAA,GACNJ,KAAA,CAAMK,kBAAA,IAAsBL,KAAA,CAAMM,eAAA;AAI/B,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,MAAMC,MAAA,GAASX,KAAA,CAAMY,MAAA,CAAYH,YAAA,IAAgBD,YAAY;EAC7DL,4BAAA,CAA6B,MAAM;IACjCQ,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOR,KAAA,CAAMc,WAAA,CACXJ,iBAAA,GACI,IAAIK,IAAA,KAASJ,MAAA,CAAOE,OAAA,EAASG,KAAA,CAAM,MAAMD,IAAI,IAC7C,MAAMJ,MAAA,CAAOE,OAAA,EACjB,EACF;AACF","ignoreList":[]}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
var isServer = typeof window
|
|
3
|
-
|
|
2
|
+
var isServer = typeof window === "undefined";
|
|
3
|
+
var useIsomorphicInsertionEffect = isServer ? React.useEffect : React.useInsertionEffect || React.useLayoutEffect;
|
|
4
4
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
5
|
-
var curRef = React.useRef(initialValue
|
|
6
|
-
|
|
5
|
+
var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
|
|
6
|
+
useIsomorphicInsertionEffect(function () {
|
|
7
7
|
curRef.current = currentValue;
|
|
8
|
-
})
|
|
9
|
-
|
|
8
|
+
});
|
|
9
|
+
return React.useCallback(forwardToFunction ? function () {
|
|
10
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
+
args[_key] = arguments[_key];
|
|
12
|
+
}
|
|
10
13
|
var _curRef_current;
|
|
11
14
|
return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
|
|
12
15
|
} : function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key","_curRef_current"
|
|
1
|
+
{"version":3,"names":["React","isServer","window","useIsomorphicInsertionEffect","useEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key","_curRef_current"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,IAAAC,QAAM,UAAWC,MAAO,gBAAW;AAMnC,IAAAC,4BAAM,GAAAF,QAA+B,GAAAD,KACjC,CAAAI,SAAM,GAAAJ,KACN,CAAAK,kBAAM,IAAAL,KAAsB,CAAAM,eAAM;AAI/B,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,IAAAC,MAAM,GAAAX,KAAS,CAAAY,MAAM,CAAAH,YAAY,SAAgB,IAAAA,YAAY,cAAAA,YAAA,GAAAD,YAAA;EAC7DL,4BAAA,CAA6B,YAAM;IACjCQ,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOR,KAAA,CAAMc,WAAA,CAAAJ,iBAAA;IACX,SAAAK,IAAA,GAAAC,SACQ,CAAAC,MAAA,EAASC,IAAA,GAAO,IAAAC,KAAS,CAAAJ,IAAM,GAAAK,IAAM,GAAI,GAAAA,IAC7C,GAAML,IAAA,EAAAK,IAAO;MAChBF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACH;IACF,IAAAC,eAAA","ignoreList":[]}
|