@hanzo/gui-use-callback-ref 2.0.0-rc.29

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ useCallbackRef: () => useCallbackRef
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var React = __toESM(require("react"), 1);
38
+ function useCallbackRef(callback) {
39
+ const callbackRef = React.useRef(callback);
40
+ return React.useEffect(() => {
41
+ callbackRef.current = callback;
42
+ }), React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
43
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var index_exports = {};
35
+ __export(index_exports, {
36
+ useCallbackRef: () => useCallbackRef
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+ var React = __toESM(require("react"), 1);
40
+ function useCallbackRef(callback) {
41
+ var callbackRef = React.useRef(callback);
42
+ return React.useEffect(function () {
43
+ callbackRef.current = callback;
44
+ }), React.useMemo(function () {
45
+ return function () {
46
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
47
+ var _callbackRef_current;
48
+ return (_callbackRef_current = callbackRef.current) === null || _callbackRef_current === void 0 ? void 0 : _callbackRef_current.call(callbackRef, ...args);
49
+ };
50
+ }, []);
51
+ }
52
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","useCallbackRef","module","exports","React","__toESM","require","callback","callbackRef","useRef","useEffect","current","useMemo"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,cAAA,EAAAA,CAAA,KAAAA;AAAA;AAEAC,MAAA,CAAAC,OAAuB,GAAAT,YAAA,CAAAK,aAAA;AAMhB,IAAAK,KAAS,GAAAC,OAAA,CAAAC,OACd,QACG;AACH,SAAML,cAAcA,CAAAM,QAAM;EAE1B,IAAAC,WAAM,GAAAJ,KAAU,CAAAK,MAAM,CAAAF,QAAA;EACpB,OAAAH,KAAA,CAAAM,SAAY,aAAU;IACvBF,WAGY,CAAAG,OAAQ,GAAAJ,QAAW;EAClC,IAAAH,KAAA,CAAAQ,OAAA","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ function useCallbackRef(callback) {
3
+ const callbackRef = React.useRef(callback);
4
+ return React.useEffect(() => {
5
+ callbackRef.current = callback;
6
+ }), React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
7
+ }
8
+ export { useCallbackRef };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallbackRef","callback","callbackRef","useRef","useEffect","current","useMemo","args"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAMhB,SAASC,eACdC,QAAA,EACG;EACH,MAAMC,WAAA,GAAcH,KAAA,CAAMI,MAAA,CAAOF,QAAQ;EAEzC,OAAAF,KAAA,CAAMK,SAAA,CAAU,MAAM;IACpBF,WAAA,CAAYG,OAAA,GAAUJ,QAAA;EACxB,CAAC,GAGMF,KAAA,CAAMO,OAAA,CAAQ,MAAO,IAAIC,IAAA,KAASL,WAAA,CAAYG,OAAA,GAAU,GAAGE,IAAI,GAAS,EAAE;AACnF","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ function useCallbackRef(callback) {
3
+ const callbackRef = React.useRef(callback);
4
+ return React.useEffect(() => {
5
+ callbackRef.current = callback;
6
+ }), React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
7
+ }
8
+ export { useCallbackRef };
9
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallbackRef","callback","callbackRef","useRef","useEffect","current","useMemo","args"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAMhB,SAASC,eACdC,QAAA,EACG;EACH,MAAMC,WAAA,GAAcH,KAAA,CAAMI,MAAA,CAAOF,QAAQ;EAEzC,OAAAF,KAAA,CAAMK,SAAA,CAAU,MAAM;IACpBF,WAAA,CAAYG,OAAA,GAAUJ,QAAA;EACxB,CAAC,GAGMF,KAAA,CAAMO,OAAA,CAAQ,MAAO,IAAIC,IAAA,KAASL,WAAA,CAAYG,OAAA,GAAU,GAAGE,IAAI,GAAS,EAAE;AACnF","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ function useCallbackRef(callback) {
3
+ var callbackRef = React.useRef(callback);
4
+ return React.useEffect(function () {
5
+ callbackRef.current = callback;
6
+ }), React.useMemo(function () {
7
+ return function () {
8
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
9
+ var _callbackRef_current;
10
+ return (_callbackRef_current = callbackRef.current) === null || _callbackRef_current === void 0 ? void 0 : _callbackRef_current.call(callbackRef, ...args);
11
+ };
12
+ }, []);
13
+ }
14
+ export { useCallbackRef };
15
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallbackRef","callback","callbackRef","useRef","useEffect","current","useMemo"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAMhB,SAASC,eACdC,QAAA,EACG;EACH,IAAAC,WAAM,GAAAH,KAAc,CAAAI,MAAM,CAAAF,QAAO;EAEjC,OAAAF,KAAA,CAAMK,SAAA,CAAU,YAAM;IACpBF,WAAA,CAAYG,OAAA,GAAUJ,QAAA;EACxB,CAAC,GAGMF,KAAA,CAAMO,OAAA,CAAQ,YAAW;IAClC","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@hanzo/gui-use-callback-ref",
3
+ "version": "2.0.0-rc.29",
4
+ "files": [
5
+ "src",
6
+ "types",
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "main": "dist/cjs",
12
+ "module": "dist/esm",
13
+ "types": "./types/index.d.ts",
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./types/index.d.ts",
18
+ "react-native": "./dist/esm/index.native.js",
19
+ "browser": "./dist/esm/index.mjs",
20
+ "module": "./dist/esm/index.mjs",
21
+ "import": "./dist/esm/index.mjs",
22
+ "require": "./dist/cjs/index.cjs",
23
+ "default": "./dist/esm/index.mjs"
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "hanzo-gui-build",
31
+ "watch": "hanzo-gui-build --watch",
32
+ "clean": "hanzo-gui-build clean",
33
+ "clean:build": "hanzo-gui-build clean:build"
34
+ },
35
+ "devDependencies": {
36
+ "@hanzo/gui-build": "2.0.0-rc.29",
37
+ "react": ">=19"
38
+ },
39
+ "peerDependencies": {
40
+ "react": ">=19"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ // via radix-ui
2
+
3
+ import * as React from 'react'
4
+
5
+ /**
6
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
7
+ * prop or avoid re-executing effects when passed as a dependency
8
+ */
9
+ export function useCallbackRef<T extends (...args: any[]) => any>(
10
+ callback: T | undefined
11
+ ): T {
12
+ const callbackRef = React.useRef(callback)
13
+
14
+ React.useEffect(() => {
15
+ callbackRef.current = callback
16
+ })
17
+
18
+ // https://github.com/facebook/react/issues/19240
19
+ return React.useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, [])
20
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
3
+ * prop or avoid re-executing effects when passed as a dependency
4
+ */
5
+ export declare function useCallbackRef<T extends (...args: any[]) => any>(callback: T | undefined): T;
6
+
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": ";;;;AAQA,OAAO,iBAAS,eAAe,WAAW,GAAG,qBAC3C,UAAU,gBACT",
3
+ "names": [],
4
+ "sources": [
5
+ "src/index.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "// via radix-ui\n\nimport * as React from 'react'\n\n/**\n * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a\n * prop or avoid re-executing effects when passed as a dependency\n */\nexport function useCallbackRef<T extends (...args: any[]) => any>(\n callback: T | undefined\n): T {\n const callbackRef = React.useRef(callback)\n\n React.useEffect(() => {\n callbackRef.current = callback\n })\n\n // https://github.com/facebook/react/issues/19240\n return React.useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, [])\n}\n"
10
+ ]
11
+ }