@radix-ui/react-use-effect-event 0.0.1-rc.1744998943107 → 0.0.1

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 CHANGED
@@ -30,20 +30,41 @@ 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: () => useEffectEvent
33
+ useEffectEvent: () => useEffectEvent2
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
- function useEffectEvent(callback) {
40
+ function useEffectEvent2(callback) {
41
+ if (typeof React[new OpaqueString("useEffectEvent").toString()] === "function") {
42
+ return React.useEffectEvent(callback);
43
+ }
41
44
  const ref = React.useRef(() => {
42
45
  throw new Error("Cannot call an event handler while rendering.");
43
46
  });
47
+ if (typeof React[new OpaqueString("useInsertionEffect").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
+ }
44
56
  (0, import_react_use_layout_effect.useLayoutEffect)(() => {
45
57
  ref.current = callback;
46
58
  });
47
59
  return React.useMemo(() => (...args) => ref.current?.(...args), []);
48
60
  }
61
+ var OpaqueString = class {
62
+ string;
63
+ constructor(string) {
64
+ this.string = string;
65
+ }
66
+ toString() {
67
+ return this.string;
68
+ }
69
+ };
49
70
  //# 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 // https://github.com/radix-ui/primitives/issues/3485\n // 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 // https://github.com/radix-ui/primitives/issues/3485\n // 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 useLayoutEffect(() => {\n ref.current = callback;\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;AAQhB,SAAS,eAAsC,UAAiB;AAQrE,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAaD,sDAAgB,MAAM;AACpB,QAAI,UAAU;AAAA,EAChB,CAAC;AAGD,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;",
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/**\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 // See https://github.com/webpack/webpack/issues/14814\n if (typeof (React as any)[new OpaqueString('useEffectEvent').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 // See https://github.com/webpack/webpack/issues/14814\n if (typeof (React as any)[new OpaqueString('useInsertionEffect').toString()] === 'function') {\n React.useInsertionEffect(() => {\n ref.current = callback;\n });\n } else {\n useLayoutEffect(() => {\n ref.current = callback;\n });\n }\n\n useLayoutEffect(() => {\n ref.current = callback;\n });\n\n // https://github.com/facebook/react/issues/19240\n return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);\n}\n\nclass OpaqueString {\n private string: string;\n constructor(string: string) {\n this.string = string;\n }\n toString() {\n return this.string;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAAA;AAAA;AAAA;;;ACCA,qCAAgC;AAChC,YAAuB;AAQhB,SAASC,gBAAsC,UAAiB;AAErE,MAAI,OAAQ,MAAc,IAAI,aAAa,gBAAgB,EAAE,SAAS,CAAC,MAAM,YAAY;AAEvF,WAAa,qBAAe,QAAQ;AAAA,EACtC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAQ,MAAc,IAAI,aAAa,oBAAoB,EAAE,SAAS,CAAC,MAAM,YAAY;AAC3F,IAAM,yBAAmB,MAAM;AAC7B,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH,OAAO;AACL,wDAAgB,MAAM;AACpB,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH;AAEA,sDAAgB,MAAM;AACpB,QAAI,UAAU;AAAA,EAChB,CAAC;AAGD,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;AAEA,IAAM,eAAN,MAAmB;AAAA,EACT;AAAA,EACR,YAAY,QAAgB;AAC1B,SAAK,SAAS;AAAA,EAChB;AAAA,EACA,WAAW;AACT,WAAO,KAAK;AAAA,EACd;AACF;",
6
+ "names": ["useEffectEvent", "useEffectEvent"]
7
7
  }
package/dist/index.mjs CHANGED
@@ -1,16 +1,37 @@
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
- function useEffectEvent(callback) {
4
+ function useEffectEvent2(callback) {
5
+ if (typeof React[new OpaqueString("useEffectEvent").toString()] === "function") {
6
+ return React.useEffectEvent(callback);
7
+ }
5
8
  const ref = React.useRef(() => {
6
9
  throw new Error("Cannot call an event handler while rendering.");
7
10
  });
11
+ if (typeof React[new OpaqueString("useInsertionEffect").toString()] === "function") {
12
+ React.useInsertionEffect(() => {
13
+ ref.current = callback;
14
+ });
15
+ } else {
16
+ useLayoutEffect(() => {
17
+ ref.current = callback;
18
+ });
19
+ }
8
20
  useLayoutEffect(() => {
9
21
  ref.current = callback;
10
22
  });
11
23
  return React.useMemo(() => (...args) => ref.current?.(...args), []);
12
24
  }
25
+ var OpaqueString = class {
26
+ string;
27
+ constructor(string) {
28
+ this.string = string;
29
+ }
30
+ toString() {
31
+ return this.string;
32
+ }
33
+ };
13
34
  export {
14
- useEffectEvent
35
+ useEffectEvent2 as useEffectEvent
15
36
  };
16
37
  //# sourceMappingURL=index.mjs.map
@@ -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 // https://github.com/radix-ui/primitives/issues/3485\n // 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 // https://github.com/radix-ui/primitives/issues/3485\n // 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 useLayoutEffect(() => {\n ref.current = callback;\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,SAAS,eAAsC,UAAiB;AAQrE,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAaD,kBAAgB,MAAM;AACpB,QAAI,UAAU;AAAA,EAChB,CAAC;AAGD,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;",
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/**\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 // See https://github.com/webpack/webpack/issues/14814\n if (typeof (React as any)[new OpaqueString('useEffectEvent').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 // See https://github.com/webpack/webpack/issues/14814\n if (typeof (React as any)[new OpaqueString('useInsertionEffect').toString()] === 'function') {\n React.useInsertionEffect(() => {\n ref.current = callback;\n });\n } else {\n useLayoutEffect(() => {\n ref.current = callback;\n });\n }\n\n useLayoutEffect(() => {\n ref.current = callback;\n });\n\n // https://github.com/facebook/react/issues/19240\n return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);\n}\n\nclass OpaqueString {\n private string: string;\n constructor(string: string) {\n this.string = string;\n }\n toString() {\n return this.string;\n }\n}\n"],
5
+ "mappings": ";AACA,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAQhB,SAASA,gBAAsC,UAAiB;AAErE,MAAI,OAAQ,MAAc,IAAI,aAAa,gBAAgB,EAAE,SAAS,CAAC,MAAM,YAAY;AAEvF,WAAa,qBAAe,QAAQ;AAAA,EACtC;AAEA,QAAM,MAAY,aAAgC,MAAM;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE,CAAC;AAED,MAAI,OAAQ,MAAc,IAAI,aAAa,oBAAoB,EAAE,SAAS,CAAC,MAAM,YAAY;AAC3F,IAAM,yBAAmB,MAAM;AAC7B,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH,OAAO;AACL,oBAAgB,MAAM;AACpB,UAAI,UAAU;AAAA,IAChB,CAAC;AAAA,EACH;AAEA,kBAAgB,MAAM;AACpB,QAAI,UAAU;AAAA,EAChB,CAAC;AAGD,SAAa,cAAQ,MAAO,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC3E;AAEA,IAAM,eAAN,MAAmB;AAAA,EACT;AAAA,EACR,YAAY,QAAgB;AAC1B,SAAK,SAAS;AAAA,EAChB;AAAA,EACA,WAAW;AACT,WAAO,KAAK;AAAA,EACd;AACF;",
6
+ "names": ["useEffectEvent"]
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.1-rc.1744998943107",
3
+ "version": "0.0.1",
4
4
  "license": "MIT",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -28,11 +28,11 @@
28
28
  "@types/react-dom": "^19.0.3",
29
29
  "@types/use-sync-external-store": "^0.0.6",
30
30
  "eslint": "^9.18.0",
31
- "react": "^19.0.0",
32
- "react-dom": "^19.0.0",
31
+ "react": "^19.1.0",
32
+ "react-dom": "^19.1.0",
33
33
  "typescript": "^5.7.3",
34
- "@repo/builder": "0.0.0",
35
34
  "@repo/eslint-config": "0.0.0",
35
+ "@repo/builder": "0.0.0",
36
36
  "@repo/typescript-config": "0.0.0"
37
37
  },
38
38
  "homepage": "https://radix-ui.com/primitives",
@@ -9,27 +9,25 @@ type AnyFunction = (...args: any[]) => any;
9
9
  * as possible until its stable release, and back-fill it as a shim as needed.
10
10
  */
11
11
  export function useEffectEvent<T extends AnyFunction>(callback?: T): T {
12
- // https://github.com/radix-ui/primitives/issues/3485
13
12
  // See https://github.com/webpack/webpack/issues/14814
14
- // if (typeof React['useEffectEvent '.trim().toString()] === 'function') {
15
- // // @ts-expect-error
16
- // return React.useEffectEvent(callback);
17
- // }
13
+ if (typeof (React as any)[new OpaqueString('useEffectEvent').toString()] === 'function') {
14
+ // @ts-expect-error
15
+ return React.useEffectEvent(callback);
16
+ }
18
17
 
19
18
  const ref = React.useRef<AnyFunction | undefined>(() => {
20
19
  throw new Error('Cannot call an event handler while rendering.');
21
20
  });
22
- // https://github.com/radix-ui/primitives/issues/3485
23
21
  // See https://github.com/webpack/webpack/issues/14814
24
- // if (typeof React['useInsertionEffect '.trim().toString()] === 'function') {
25
- // React.useInsertionEffect(() => {
26
- // ref.current = callback;
27
- // });
28
- // } else {
29
- // useLayoutEffect(() => {
30
- // ref.current = callback;
31
- // });
32
- // }
22
+ if (typeof (React as any)[new OpaqueString('useInsertionEffect').toString()] === 'function') {
23
+ React.useInsertionEffect(() => {
24
+ ref.current = callback;
25
+ });
26
+ } else {
27
+ useLayoutEffect(() => {
28
+ ref.current = callback;
29
+ });
30
+ }
33
31
 
34
32
  useLayoutEffect(() => {
35
33
  ref.current = callback;
@@ -38,3 +36,13 @@ export function useEffectEvent<T extends AnyFunction>(callback?: T): T {
38
36
  // https://github.com/facebook/react/issues/19240
39
37
  return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);
40
38
  }
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
+ }