@tamagui/use-callback-ref 1.45.9

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.
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ useCallbackRef: () => useCallbackRef
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+ var React = __toESM(require("react"));
35
+ function useCallbackRef(callback) {
36
+ const callbackRef = React.useRef(callback);
37
+ React.useEffect(() => {
38
+ callbackRef.current = callback;
39
+ });
40
+ return React.useMemo(() => (...args) => {
41
+ var _a;
42
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
43
+ }, []);
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ useCallbackRef
48
+ });
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAMhB,SAAS,eACd,UACG;AACH,QAAM,cAAc,MAAM,OAAO,QAAQ;AAEzC,QAAM,UAAU,MAAM;AACpB,gBAAY,UAAU;AAAA,EACxB,CAAC;AAGD,SAAO,MAAM,QAAQ,MAAO,IAAI,SAAM;AAlBxC;AAkB2C,6BAAY,YAAZ,qCAAsB,GAAG;AAAA,KAAa,CAAC,CAAC;AACnF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ function useCallbackRef(callback) {
3
+ const callbackRef = React.useRef(callback);
4
+ React.useEffect(() => {
5
+ callbackRef.current = callback;
6
+ });
7
+ return React.useMemo(() => (...args) => {
8
+ var _a;
9
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
10
+ }, []);
11
+ }
12
+ export {
13
+ useCallbackRef
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAEA,YAAY,WAAW;AAMhB,SAAS,eACd,UACG;AACH,QAAM,cAAc,MAAM,OAAO,QAAQ;AAEzC,QAAM,UAAU,MAAM;AACpB,gBAAY,UAAU;AAAA,EACxB,CAAC;AAGD,SAAO,MAAM,QAAQ,MAAO,IAAI,SAAM;AAlBxC;AAkB2C,6BAAY,YAAZ,qCAAsB,GAAG;AAAA,KAAa,CAAC,CAAC;AACnF;",
5
+ "names": []
6
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@tamagui/use-callback-ref",
3
+ "version": "1.45.9",
4
+ "types": "./types/index.d.ts",
5
+ "main": "dist/cjs",
6
+ "module": "dist/esm",
7
+ "files": [
8
+ "src",
9
+ "types",
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tamagui-build",
14
+ "watch": "tamagui-build --watch",
15
+ "lint": "../../node_modules/.bin/rome check src",
16
+ "lint:fix": "../../node_modules/.bin/rome check --apply src",
17
+ "clean": "tamagui-build clean",
18
+ "clean:build": "tamagui-build clean:build"
19
+ },
20
+ "devDependencies": {
21
+ "@tamagui/build": "1.45.9"
22
+ },
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "types": "./types/index.d.ts",
27
+ "import": "./dist/esm/index.js",
28
+ "require": "./dist/cjs/index.js"
29
+ }
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
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,6 @@
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
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC9D,QAAQ,EAAE,CAAC,GAAG,SAAS,GACtB,CAAC,CASH"}