@tamagui/use-constant 1.0.1-beta.194
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 +39 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +7 -0
- package/package.json +30 -0
- package/src/index.ts +19 -0
- package/types/index.d.ts +2 -0
- package/types/useDirection.d.ts +11 -0
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
});
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
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;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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
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,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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/use-constant",
|
|
3
|
+
"version": "1.0.1-beta.194",
|
|
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": "eslint",
|
|
16
|
+
"lint:fix": "yarn lint --fix",
|
|
17
|
+
"clean": "tamagui-build clean",
|
|
18
|
+
"clean:build": "tamagui-build clean:build"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tamagui/build": "^1.0.1-beta.194",
|
|
22
|
+
"react": "*"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "*"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
type ResultBox<T> = { v: T }
|
|
4
|
+
|
|
5
|
+
export function useConstant<T>(fn: () => T): T {
|
|
6
|
+
// RSC compat
|
|
7
|
+
if (typeof document === 'undefined') {
|
|
8
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
|
+
return useMemo(() => fn(), [])
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ref = useRef<ResultBox<T>>()
|
|
13
|
+
|
|
14
|
+
if (!ref.current) {
|
|
15
|
+
ref.current = { v: fn() }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return ref.current.v
|
|
19
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
declare type Direction = 'ltr' | 'rtl';
|
|
3
|
+
interface DirectionProviderProps {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
dir: Direction;
|
|
6
|
+
}
|
|
7
|
+
export declare const DirectionProvider: React.FC<DirectionProviderProps>;
|
|
8
|
+
export declare function useDirection(localDir?: Direction): Direction;
|
|
9
|
+
export declare const Provider: React.FC<DirectionProviderProps>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useDirection.d.ts.map
|