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

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,29 +30,20 @@ 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: () => useEffectEvent2
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
- function useEffectEvent2(callback) {
41
- if (typeof React["useEffectEvent ".trim().toString()] === "function") {
42
- return React.useEffectEvent(callback);
43
- }
40
+ function useEffectEvent(callback) {
44
41
  const ref = React.useRef(() => {
45
42
  throw new Error("Cannot call an event handler while rendering.");
46
43
  });
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
- }
44
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
45
+ ref.current = callback;
46
+ });
56
47
  return React.useMemo(() => (...args) => ref.current?.(...args), []);
57
48
  }
58
49
  //# 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 // @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"]
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": []
7
7
  }
package/dist/index.mjs CHANGED
@@ -1,25 +1,16 @@
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 useEffectEvent2(callback) {
5
- if (typeof React["useEffectEvent ".trim().toString()] === "function") {
6
- return React.useEffectEvent(callback);
7
- }
4
+ function useEffectEvent(callback) {
8
5
  const ref = React.useRef(() => {
9
6
  throw new Error("Cannot call an event handler while rendering.");
10
7
  });
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
- }
8
+ useLayoutEffect(() => {
9
+ ref.current = callback;
10
+ });
20
11
  return React.useMemo(() => (...args) => ref.current?.(...args), []);
21
12
  }
22
13
  export {
23
- useEffectEvent2 as useEffectEvent
14
+ useEffectEvent
24
15
  };
25
16
  //# 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 // @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"]
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": []
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.0",
3
+ "version": "0.0.1-rc.1744998943107",
4
4
  "license": "MIT",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -31,8 +31,8 @@
31
31
  "react": "^19.0.0",
32
32
  "react-dom": "^19.0.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",
@@ -9,25 +9,31 @@ 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
- // @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
- }
12
+ // https://github.com/radix-ui/primitives/issues/3485
13
+ // 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
+ // }
17
18
 
18
19
  const ref = React.useRef<AnyFunction | undefined>(() => {
19
20
  throw new Error('Cannot call an event handler while rendering.');
20
21
  });
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
- }
22
+ // https://github.com/radix-ui/primitives/issues/3485
23
+ // 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
+ // }
33
+
34
+ useLayoutEffect(() => {
35
+ ref.current = callback;
36
+ });
31
37
 
32
38
  // https://github.com/facebook/react/issues/19240
33
39
  return React.useMemo(() => ((...args) => ref.current?.(...args)) as T, []);