@tamagui/use-constant 1.14.1 → 1.14.2

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.js CHANGED
@@ -1,2 +1,39 @@
1
- "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var i=(t,e)=>{for(var u in e)o(t,u,{get:e[u],enumerable:!0})},m=(t,e,u,f)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!T.call(t,r)&&r!==u&&o(t,r,{get:()=>e[r],enumerable:!(f=s(e,r))||f.enumerable});return t};var p=t=>m(o({},"__esModule",{value:!0}),t);var v={};i(v,{useConstant:()=>d});module.exports=p(v);var n=require("react");function d(t){if(typeof document>"u")return(0,n.useMemo)(()=>t(),[]);const e=(0,n.useRef)();return e.current||(e.current={v:t()}),e.current.v}0&&(module.exports={useConstant});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ useConstant: () => useConstant
22
+ });
23
+ module.exports = __toCommonJS(src_exports);
24
+ var import_react = require("react");
25
+ function useConstant(fn) {
26
+ if (typeof document === "undefined") {
27
+ return (0, import_react.useMemo)(() => fn(), []);
28
+ }
29
+ const ref = (0, import_react.useRef)();
30
+ if (!ref.current) {
31
+ ref.current = { v: fn() };
32
+ }
33
+ return ref.current.v;
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ useConstant
38
+ });
2
39
  //# sourceMappingURL=index.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["import { useMemo, useRef } from 'react'\n\ntype ResultBox<T> = { v: T }\n\nexport function useConstant<T>(fn: () => T): T {\n // RSC compat\n if (typeof document === 'undefined') {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => fn(), [])\n }\n\n const ref = useRef<ResultBox<T>>()\n\n if (!ref.current) {\n ref.current = { v: fn() }\n }\n\n return ref.current.v\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,iBAIzB,SAASF,EAAeG,EAAgB,CAE7C,GAAI,OAAO,SAAa,IAEtB,SAAO,WAAQ,IAAMA,EAAG,EAAG,CAAC,CAAC,EAG/B,MAAMC,KAAM,UAAqB,EAEjC,OAAKA,EAAI,UACPA,EAAI,QAAU,CAAE,EAAGD,EAAG,CAAE,GAGnBC,EAAI,QAAQ,CACrB",
6
- "names": ["src_exports", "__export", "useConstant", "__toCommonJS", "import_react", "fn", "ref"]
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAIzB,SAAS,YAAe,IAAgB;AAE7C,MAAI,OAAO,aAAa,aAAa;AAEnC,eAAO,sBAAQ,MAAM,GAAG,GAAG,CAAC,CAAC;AAAA,EAC/B;AAEA,QAAM,UAAM,qBAAqB;AAEjC,MAAI,CAAC,IAAI,SAAS;AAChB,QAAI,UAAU,EAAE,GAAG,GAAG,EAAE;AAAA,EAC1B;AAEA,SAAO,IAAI,QAAQ;AACrB;",
6
+ "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,15 @@
1
- import{useMemo as r,useRef as u}from"react";function o(t){if(typeof document>"u")return r(()=>t(),[]);const e=u();return e.current||(e.current={v:t()}),e.current.v}export{o as useConstant};
1
+ import { useMemo, useRef } from "react";
2
+ function useConstant(fn) {
3
+ if (typeof document === "undefined") {
4
+ return useMemo(() => fn(), []);
5
+ }
6
+ const ref = useRef();
7
+ if (!ref.current) {
8
+ ref.current = { v: fn() };
9
+ }
10
+ return ref.current.v;
11
+ }
12
+ export {
13
+ useConstant
14
+ };
2
15
  //# sourceMappingURL=index.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["import { useMemo, useRef } from 'react'\n\ntype ResultBox<T> = { v: T }\n\nexport function useConstant<T>(fn: () => T): T {\n // RSC compat\n if (typeof document === 'undefined') {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => fn(), [])\n }\n\n const ref = useRef<ResultBox<T>>()\n\n if (!ref.current) {\n ref.current = { v: fn() }\n }\n\n return ref.current.v\n}\n"],
5
- "mappings": "AAAA,OAAS,WAAAA,EAAS,UAAAC,MAAc,QAIzB,SAASC,EAAeC,EAAgB,CAE7C,GAAI,OAAO,SAAa,IAEtB,OAAOH,EAAQ,IAAMG,EAAG,EAAG,CAAC,CAAC,EAG/B,MAAMC,EAAMH,EAAqB,EAEjC,OAAKG,EAAI,UACPA,EAAI,QAAU,CAAE,EAAGD,EAAG,CAAE,GAGnBC,EAAI,QAAQ,CACrB",
6
- "names": ["useMemo", "useRef", "useConstant", "fn", "ref"]
5
+ "mappings": "AAAA,SAAS,SAAS,cAAc;AAIzB,SAAS,YAAe,IAAgB;AAE7C,MAAI,OAAO,aAAa,aAAa;AAEnC,WAAO,QAAQ,MAAM,GAAG,GAAG,CAAC,CAAC;AAAA,EAC/B;AAEA,QAAM,MAAM,OAAqB;AAEjC,MAAI,CAAC,IAAI,SAAS;AAChB,QAAI,UAAU,EAAE,GAAG,GAAG,EAAE;AAAA,EAC1B;AAEA,SAAO,IAAI,QAAQ;AACrB;",
6
+ "names": []
7
7
  }
@@ -1,2 +1,15 @@
1
- import{useMemo as r,useRef as u}from"react";function o(t){if(typeof document>"u")return r(()=>t(),[]);const e=u();return e.current||(e.current={v:t()}),e.current.v}export{o as useConstant};
1
+ import { useMemo, useRef } from "react";
2
+ function useConstant(fn) {
3
+ if (typeof document === "undefined") {
4
+ return useMemo(() => fn(), []);
5
+ }
6
+ const ref = useRef();
7
+ if (!ref.current) {
8
+ ref.current = { v: fn() };
9
+ }
10
+ return ref.current.v;
11
+ }
12
+ export {
13
+ useConstant
14
+ };
2
15
  //# sourceMappingURL=index.mjs.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["import { useMemo, useRef } from 'react'\n\ntype ResultBox<T> = { v: T }\n\nexport function useConstant<T>(fn: () => T): T {\n // RSC compat\n if (typeof document === 'undefined') {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => fn(), [])\n }\n\n const ref = useRef<ResultBox<T>>()\n\n if (!ref.current) {\n ref.current = { v: fn() }\n }\n\n return ref.current.v\n}\n"],
5
- "mappings": "AAAA,OAAS,WAAAA,EAAS,UAAAC,MAAc,QAIzB,SAASC,EAAeC,EAAgB,CAE7C,GAAI,OAAO,SAAa,IAEtB,OAAOH,EAAQ,IAAMG,EAAG,EAAG,CAAC,CAAC,EAG/B,MAAMC,EAAMH,EAAqB,EAEjC,OAAKG,EAAI,UACPA,EAAI,QAAU,CAAE,EAAGD,EAAG,CAAE,GAGnBC,EAAI,QAAQ,CACrB",
6
- "names": ["useMemo", "useRef", "useConstant", "fn", "ref"]
5
+ "mappings": "AAAA,SAAS,SAAS,cAAc;AAIzB,SAAS,YAAe,IAAgB;AAE7C,MAAI,OAAO,aAAa,aAAa;AAEnC,WAAO,QAAQ,MAAM,GAAG,GAAG,CAAC,CAAC;AAAA,EAC/B;AAEA,QAAM,MAAM,OAAqB;AAEjC,MAAI,CAAC,IAAI,SAAS;AAChB,QAAI,UAAU,EAAE,GAAG,GAAG,EAAE;AAAA,EAC1B;AAEA,SAAO,IAAI,QAAQ;AACrB;",
6
+ "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-constant",
3
- "version": "1.14.1",
3
+ "version": "1.14.2",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -26,7 +26,7 @@
26
26
  }
27
27
  },
28
28
  "devDependencies": {
29
- "@tamagui/build": "1.14.1",
29
+ "@tamagui/build": "1.14.2",
30
30
  "react": "^18.2.0"
31
31
  },
32
32
  "peerDependencies": {