@radix-ui/react-use-effect-event 0.0.0

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) 2022 WorkOS
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.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `react-use-is-hydrated`
2
+
3
+ ## Usage
4
+
5
+ This is an internal utility, not intended for public usage.
@@ -0,0 +1,8 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ /**
3
+ * Designed to approximate the behavior on `experimental_useEffectEvent` as best
4
+ * as possible until its stable release, and back-fill it as a shim as needed.
5
+ */
6
+ declare function useEffectEvent<T extends AnyFunction>(callback?: T): T;
7
+
8
+ export { useEffectEvent };
@@ -0,0 +1,8 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ /**
3
+ * Designed to approximate the behavior on `experimental_useEffectEvent` as best
4
+ * as possible until its stable release, and back-fill it as a shim as needed.
5
+ */
6
+ declare function useEffectEvent<T extends AnyFunction>(callback?: T): T;
7
+
8
+ export { useEffectEvent };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
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
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ useEffectEvent: () => useEffectEvent2
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/use-effect-event.tsx
38
+ var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
39
+ var React = __toESM(require("react"));
40
+ function useEffectEvent2(callback) {
41
+ if (typeof React["useEffectEvent ".trim().toString()] === "function") {
42
+ return React.useEffectEvent(callback);
43
+ }
44
+ const ref = React.useRef(() => {
45
+ throw new Error("Cannot call an event handler while rendering.");
46
+ });
47
+ if (typeof React["useInsertionEffect ".trim().toString()] === "function") {
48
+ React.useInsertionEffect(() => {
49
+ ref.current = callback;
50
+ });
51
+ } else {
52
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
53
+ ref.current = callback;
54
+ });
55
+ }
56
+ return React.useMemo(() => (...args) => ref.current?.(...args), []);
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/use-effect-event.tsx"],
4
+ "sourcesContent": ["export { useEffectEvent } from './use-effect-event';\n", "/* eslint-disable react-hooks/rules-of-hooks */\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport * as React from 'react';\n\ntype AnyFunction = (...args: any[]) => any;\n\n/**\n * Designed to approximate the behavior on `experimental_useEffectEvent` as best\n * as possible until its stable release, and back-fill it as a shim as needed.\n */\nexport function useEffectEvent<T extends AnyFunction>(callback?: T): T {\n // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814\n if (typeof React['useEffectEvent '.trim().toString()] === 'function') {\n // @ts-expect-error\n return React.useEffectEvent(callback);\n }\n\n const ref = React.useRef<AnyFunction | undefined>(() => {\n throw new Error('Cannot call an event handler while rendering.');\n });\n // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814\n if (typeof React['useInsertionEffect '.trim().toString()] === 'function') {\n React.useInsertionEffect(() => {\n ref.current = callback;\n });\n } else {\n useLayoutEffect(() => {\n ref.current = callback;\n });\n }\n\n // https://github.com/facebook/react/issues/19240\n return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAAA;AAAA;AAAA;;;ACCA,qCAAgC;AAChC,YAAuB;AAQhB,SAASC,gBAAsC,UAAiB;AAErE,MAAI,OAAO,MAAM,kBAAkB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY;AAEpE,WAAa,qBAAe,QAAQ;AAAA,EACtC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAO,MAAM,sBAAsB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY;AACxE,IAAM,yBAAmB,MAAM;AAC7B,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH,OAAO;AACL,wDAAgB,MAAM;AACpB,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH;AAGA,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;",
6
+ "names": ["useEffectEvent", "useEffectEvent"]
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,25 @@
1
+ // src/use-effect-event.tsx
2
+ import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
3
+ import * as React from "react";
4
+ function useEffectEvent2(callback) {
5
+ if (typeof React["useEffectEvent ".trim().toString()] === "function") {
6
+ return React.useEffectEvent(callback);
7
+ }
8
+ const ref = React.useRef(() => {
9
+ throw new Error("Cannot call an event handler while rendering.");
10
+ });
11
+ if (typeof React["useInsertionEffect ".trim().toString()] === "function") {
12
+ React.useInsertionEffect(() => {
13
+ ref.current = callback;
14
+ });
15
+ } else {
16
+ useLayoutEffect(() => {
17
+ ref.current = callback;
18
+ });
19
+ }
20
+ return React.useMemo(() => (...args) => ref.current?.(...args), []);
21
+ }
22
+ export {
23
+ useEffectEvent2 as useEffectEvent
24
+ };
25
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/use-effect-event.tsx"],
4
+ "sourcesContent": ["/* eslint-disable react-hooks/rules-of-hooks */\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport * as React from 'react';\n\ntype AnyFunction = (...args: any[]) => any;\n\n/**\n * Designed to approximate the behavior on `experimental_useEffectEvent` as best\n * as possible until its stable release, and back-fill it as a shim as needed.\n */\nexport function useEffectEvent<T extends AnyFunction>(callback?: T): T {\n // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814\n if (typeof React['useEffectEvent '.trim().toString()] === 'function') {\n // @ts-expect-error\n return React.useEffectEvent(callback);\n }\n\n const ref = React.useRef<AnyFunction | undefined>(() => {\n throw new Error('Cannot call an event handler while rendering.');\n });\n // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814\n if (typeof React['useInsertionEffect '.trim().toString()] === 'function') {\n React.useInsertionEffect(() => {\n ref.current = callback;\n });\n } else {\n useLayoutEffect(() => {\n ref.current = callback;\n });\n }\n\n // https://github.com/facebook/react/issues/19240\n return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);\n}\n"],
5
+ "mappings": ";AACA,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAQhB,SAASA,gBAAsC,UAAiB;AAErE,MAAI,OAAO,MAAM,kBAAkB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY;AAEpE,WAAa,qBAAe,QAAQ;AAAA,EACtC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAO,MAAM,sBAAsB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY;AACxE,IAAM,yBAAmB,MAAM;AAC7B,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH,OAAO;AACL,oBAAgB,MAAM;AACpB,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH;AAGA,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;",
6
+ "names": ["useEffectEvent"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@radix-ui/react-use-effect-event",
3
+ "version": "0.0.0",
4
+ "license": "MIT",
5
+ "source": "./src/index.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "files": [
9
+ "src",
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "sideEffects": false,
14
+ "peerDependencies": {
15
+ "@types/react": "*",
16
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
17
+ },
18
+ "peerDependenciesMeta": {
19
+ "@types/react": {
20
+ "optional": true
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "@radix-ui/react-use-layout-effect": "1.1.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^19.0.7",
28
+ "@types/react-dom": "^19.0.3",
29
+ "@types/use-sync-external-store": "^0.0.6",
30
+ "eslint": "^9.18.0",
31
+ "react": "^19.0.0",
32
+ "react-dom": "^19.0.0",
33
+ "typescript": "^5.7.3",
34
+ "@repo/eslint-config": "0.0.0",
35
+ "@repo/builder": "0.0.0",
36
+ "@repo/typescript-config": "0.0.0"
37
+ },
38
+ "homepage": "https://radix-ui.com/primitives",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/radix-ui/primitives.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/radix-ui/primitives/issues"
45
+ },
46
+ "scripts": {
47
+ "lint": "eslint --max-warnings 0 src",
48
+ "clean": "rm -rf dist",
49
+ "typecheck": "tsc --noEmit",
50
+ "build": "radix-build"
51
+ },
52
+ "types": "./dist/index.d.ts",
53
+ "exports": {
54
+ ".": {
55
+ "import": {
56
+ "types": "./dist/index.d.mts",
57
+ "default": "./dist/index.mjs"
58
+ },
59
+ "require": {
60
+ "types": "./dist/index.d.ts",
61
+ "default": "./dist/index.js"
62
+ }
63
+ }
64
+ }
65
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { useEffectEvent } from './use-effect-event';
@@ -0,0 +1,34 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
2
+ import { useLayoutEffect } from '@radix-ui/react-use-layout-effect';
3
+ import * as React from 'react';
4
+
5
+ type AnyFunction = (...args: any[]) => any;
6
+
7
+ /**
8
+ * Designed to approximate the behavior on `experimental_useEffectEvent` as best
9
+ * as possible until its stable release, and back-fill it as a shim as needed.
10
+ */
11
+ export function useEffectEvent<T extends AnyFunction>(callback?: T): T {
12
+ // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814
13
+ if (typeof React['useEffectEvent '.trim().toString()] === 'function') {
14
+ // @ts-expect-error
15
+ return React.useEffectEvent(callback);
16
+ }
17
+
18
+ const ref = React.useRef<AnyFunction | undefined>(() => {
19
+ throw new Error('Cannot call an event handler while rendering.');
20
+ });
21
+ // @ts-expect-error: See https://github.com/webpack/webpack/issues/14814
22
+ if (typeof React['useInsertionEffect '.trim().toString()] === 'function') {
23
+ React.useInsertionEffect(() => {
24
+ ref.current = callback;
25
+ });
26
+ } else {
27
+ useLayoutEffect(() => {
28
+ ref.current = callback;
29
+ });
30
+ }
31
+
32
+ // https://github.com/facebook/react/issues/19240
33
+ return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);
34
+ }