@radix-ui/react-use-effect-event 0.0.1 → 0.0.2-rc.1745002236885
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/index.js +8 -18
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +8 -18
- package/dist/index.mjs.map +3 -3
- package/package.json +2 -2
- package/src/use-effect-event.tsx +8 -20
package/dist/index.js
CHANGED
|
@@ -30,22 +30,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
useEffectEvent: () =>
|
|
33
|
+
useEffectEvent: () => useEffectEvent
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/use-effect-event.tsx
|
|
38
38
|
var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
|
|
39
39
|
var React = __toESM(require("react"));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var useReactEffectEvent = React[" useEffectEvent ".trim().toString()];
|
|
41
|
+
var useReactInsertionEffect = React[" useInsertionEffect ".trim().toString()];
|
|
42
|
+
function useEffectEvent(callback) {
|
|
43
|
+
if (typeof useReactEffectEvent === "function") {
|
|
44
|
+
return useReactEffectEvent(callback);
|
|
43
45
|
}
|
|
44
46
|
const ref = React.useRef(() => {
|
|
45
47
|
throw new Error("Cannot call an event handler while rendering.");
|
|
46
48
|
});
|
|
47
|
-
if (typeof
|
|
48
|
-
|
|
49
|
+
if (typeof useReactInsertionEffect === "function") {
|
|
50
|
+
useReactInsertionEffect(() => {
|
|
49
51
|
ref.current = callback;
|
|
50
52
|
});
|
|
51
53
|
} else {
|
|
@@ -53,18 +55,6 @@ function useEffectEvent2(callback) {
|
|
|
53
55
|
ref.current = callback;
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
|
-
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
|
|
57
|
-
ref.current = callback;
|
|
58
|
-
});
|
|
59
58
|
return React.useMemo(() => (...args) => ref.current?.(...args), []);
|
|
60
59
|
}
|
|
61
|
-
var OpaqueString = class {
|
|
62
|
-
string;
|
|
63
|
-
constructor(string) {
|
|
64
|
-
this.string = string;
|
|
65
|
-
}
|
|
66
|
-
toString() {
|
|
67
|
-
return this.string;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
60
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA
|
|
6
|
-
"names": [
|
|
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// See https://github.com/webpack/webpack/issues/14814\nconst useReactEffectEvent = (React as any)[' useEffectEvent '.trim().toString()];\nconst useReactInsertionEffect = (React as any)[' useInsertionEffect '.trim().toString()];\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 if (typeof useReactEffectEvent === 'function') {\n return useReactEffectEvent(callback);\n }\n\n const ref = React.useRef<AnyFunction | undefined>(() => {\n throw new Error('Cannot call an event handler while rendering.');\n });\n // See https://github.com/webpack/webpack/issues/14814\n if (typeof useReactInsertionEffect === 'function') {\n useReactInsertionEffect(() => {\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;AAAA;AAAA;;;ACCA,qCAAgC;AAChC,YAAuB;AAKvB,IAAM,sBAAuB,MAAc,mBAAmB,KAAK,EAAE,SAAS,CAAC;AAC/E,IAAM,0BAA2B,MAAc,uBAAuB,KAAK,EAAE,SAAS,CAAC;AAMhF,SAAS,eAAsC,UAAiB;AACrE,MAAI,OAAO,wBAAwB,YAAY;AAC7C,WAAO,oBAAoB,QAAQ;AAAA,EACrC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAO,4BAA4B,YAAY;AACjD,4BAAwB,MAAM;AAC5B,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": []
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// src/use-effect-event.tsx
|
|
2
2
|
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useReactEffectEvent = React[" useEffectEvent ".trim().toString()];
|
|
5
|
+
var useReactInsertionEffect = React[" useInsertionEffect ".trim().toString()];
|
|
6
|
+
function useEffectEvent(callback) {
|
|
7
|
+
if (typeof useReactEffectEvent === "function") {
|
|
8
|
+
return useReactEffectEvent(callback);
|
|
7
9
|
}
|
|
8
10
|
const ref = React.useRef(() => {
|
|
9
11
|
throw new Error("Cannot call an event handler while rendering.");
|
|
10
12
|
});
|
|
11
|
-
if (typeof
|
|
12
|
-
|
|
13
|
+
if (typeof useReactInsertionEffect === "function") {
|
|
14
|
+
useReactInsertionEffect(() => {
|
|
13
15
|
ref.current = callback;
|
|
14
16
|
});
|
|
15
17
|
} else {
|
|
@@ -17,21 +19,9 @@ function useEffectEvent2(callback) {
|
|
|
17
19
|
ref.current = callback;
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
|
-
useLayoutEffect(() => {
|
|
21
|
-
ref.current = callback;
|
|
22
|
-
});
|
|
23
22
|
return React.useMemo(() => (...args) => ref.current?.(...args), []);
|
|
24
23
|
}
|
|
25
|
-
var OpaqueString = class {
|
|
26
|
-
string;
|
|
27
|
-
constructor(string) {
|
|
28
|
-
this.string = string;
|
|
29
|
-
}
|
|
30
|
-
toString() {
|
|
31
|
-
return this.string;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
24
|
export {
|
|
35
|
-
|
|
25
|
+
useEffectEvent
|
|
36
26
|
};
|
|
37
27
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": ";AACA,SAAS,uBAAuB;AAChC,YAAY,WAAW;
|
|
6
|
-
"names": [
|
|
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// See https://github.com/webpack/webpack/issues/14814\nconst useReactEffectEvent = (React as any)[' useEffectEvent '.trim().toString()];\nconst useReactInsertionEffect = (React as any)[' useInsertionEffect '.trim().toString()];\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 if (typeof useReactEffectEvent === 'function') {\n return useReactEffectEvent(callback);\n }\n\n const ref = React.useRef<AnyFunction | undefined>(() => {\n throw new Error('Cannot call an event handler while rendering.');\n });\n // See https://github.com/webpack/webpack/issues/14814\n if (typeof useReactInsertionEffect === 'function') {\n useReactInsertionEffect(() => {\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;AAKvB,IAAM,sBAAuB,MAAc,mBAAmB,KAAK,EAAE,SAAS,CAAC;AAC/E,IAAM,0BAA2B,MAAc,uBAAuB,KAAK,EAAE,SAAS,CAAC;AAMhF,SAAS,eAAsC,UAAiB;AACrE,MAAI,OAAO,wBAAwB,YAAY;AAC7C,WAAO,oBAAoB,QAAQ;AAAA,EACrC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAO,4BAA4B,YAAY;AACjD,4BAAwB,MAAM;AAC5B,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": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-use-effect-event",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-rc.1745002236885",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react": "^19.1.0",
|
|
32
32
|
"react-dom": "^19.1.0",
|
|
33
33
|
"typescript": "^5.7.3",
|
|
34
|
-
"@repo/eslint-config": "0.0.0",
|
|
35
34
|
"@repo/builder": "0.0.0",
|
|
35
|
+
"@repo/eslint-config": "0.0.0",
|
|
36
36
|
"@repo/typescript-config": "0.0.0"
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://radix-ui.com/primitives",
|
package/src/use-effect-event.tsx
CHANGED
|
@@ -4,23 +4,25 @@ import * as React from 'react';
|
|
|
4
4
|
|
|
5
5
|
type AnyFunction = (...args: any[]) => any;
|
|
6
6
|
|
|
7
|
+
// See https://github.com/webpack/webpack/issues/14814
|
|
8
|
+
const useReactEffectEvent = (React as any)[' useEffectEvent '.trim().toString()];
|
|
9
|
+
const useReactInsertionEffect = (React as any)[' useInsertionEffect '.trim().toString()];
|
|
10
|
+
|
|
7
11
|
/**
|
|
8
12
|
* Designed to approximate the behavior on `experimental_useEffectEvent` as best
|
|
9
13
|
* as possible until its stable release, and back-fill it as a shim as needed.
|
|
10
14
|
*/
|
|
11
15
|
export function useEffectEvent<T extends AnyFunction>(callback?: T): T {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// @ts-expect-error
|
|
15
|
-
return React.useEffectEvent(callback);
|
|
16
|
+
if (typeof useReactEffectEvent === 'function') {
|
|
17
|
+
return useReactEffectEvent(callback);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
const ref = React.useRef<AnyFunction | undefined>(() => {
|
|
19
21
|
throw new Error('Cannot call an event handler while rendering.');
|
|
20
22
|
});
|
|
21
23
|
// See https://github.com/webpack/webpack/issues/14814
|
|
22
|
-
if (typeof
|
|
23
|
-
|
|
24
|
+
if (typeof useReactInsertionEffect === 'function') {
|
|
25
|
+
useReactInsertionEffect(() => {
|
|
24
26
|
ref.current = callback;
|
|
25
27
|
});
|
|
26
28
|
} else {
|
|
@@ -29,20 +31,6 @@ export function useEffectEvent<T extends AnyFunction>(callback?: T): T {
|
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
useLayoutEffect(() => {
|
|
33
|
-
ref.current = callback;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
34
|
// https://github.com/facebook/react/issues/19240
|
|
37
35
|
return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
class OpaqueString {
|
|
41
|
-
private string: string;
|
|
42
|
-
constructor(string: string) {
|
|
43
|
-
this.string = string;
|
|
44
|
-
}
|
|
45
|
-
toString() {
|
|
46
|
-
return this.string;
|
|
47
|
-
}
|
|
48
|
-
}
|