@open-pioneer/react-utils 4.1.0-dev.20250707115222 → 4.1.0-dev.20250818125237
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/CHANGELOG.md +3 -2
- package/TitledSection.js.map +1 -1
- package/package.json +4 -4
- package/useCommonComponentProps.js.map +1 -1
- package/useEvent.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# @open-pioneer/react-utils
|
|
2
2
|
|
|
3
|
-
## 4.1.0-dev.
|
|
3
|
+
## 4.1.0-dev.20250818125237
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- b7a854d: Update dependencies
|
|
8
8
|
- adf277b: Update dependencies
|
|
9
9
|
- Updated dependencies [b7a854d]
|
|
10
|
+
- Updated dependencies [2da02e7]
|
|
10
11
|
- Updated dependencies [adf277b]
|
|
11
|
-
- @open-pioneer/core@4.1.0-dev.
|
|
12
|
+
- @open-pioneer/core@4.1.0-dev.20250818125237
|
|
12
13
|
|
|
13
14
|
## 4.0.0
|
|
14
15
|
|
package/TitledSection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/** Properties of the {@link TitledSection} component. */\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/** The level of a html heading. */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n */\nexport function useHeadingLevel(): HeadingLevel {\n const level = useContext(LevelContext);\n if (level == null) {\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,
|
|
1
|
+
{"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/** Properties of the {@link TitledSection} component. */\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/** The level of a html heading. */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n */\nexport function useHeadingLevel(): HeadingLevel {\n const level = useContext(LevelContext);\n if (level == null) {\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,WAAA,GAAc,cAAA;AAyFpB,SAAS,cAAc,KAAA,EAAsC;AAChE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAA,EAAqB,QAAA,EAAS,GAAI,KAAA;AACjD,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,YAAY,CAAA,IAAK,CAAA;AACjD,EAAA,MAAM,OAAA,GACF,OAAO,KAAA,KAAU,QAAA,uBACZ,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAsB,QAAA,EAAA,KAAA,EAAM,CAAA,GAEhD,KAAA;AAGR,EAAA,uBACI,IAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,YAAA,GAAe,CAAA,EAC/B,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA;AAAA,GAAA,EACL,CAAA;AAER;AAmBO,SAAS,eAAe,KAAA,EAAuC;AAClE,EAAA,MAAM,EAAE,QAAA,EAAU,GAAA,EAAK,GAAG,MAAK,GAAI,KAAA;AACnC,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,GAAA,GAAM,cAAc,KAAK,CAAA;AAC/B,EAAA,2BACK,OAAA,EAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAW,GAAG,MAC3B,QAAA,EACL,CAAA;AAER;AA4CO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,GAAQ,CAAA;AAC5B,EAAA,uBAAO,GAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,KAAA,EAAQ,gBAAM,QAAA,EAAS,CAAA;AACvD;AAUO,SAAS,eAAA,GAAgC;AAC5C,EAAA,MAAM,KAAA,GAAQ,WAAW,YAAY,CAAA;AACrC,EAAA,IAAI,SAAS,IAAA,EAAM;AACf,IAAA,MAAM,IAAI,MAAM,2DAA2D,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,KAAA,EAAO,CAAC,CAAC,CAAA;AACzC;AAEA,SAAS,cAAc,KAAA,EAAyC;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA;AACpB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/react-utils",
|
|
4
|
-
"version": "4.1.0-dev.
|
|
4
|
+
"version": "4.1.0-dev.20250818125237",
|
|
5
5
|
"description": "Contains common react utilities used by the open pioneer trails project",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"directory": "src/packages/react-utils"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@chakra-ui/react": "^3.
|
|
17
|
+
"@chakra-ui/react": "^3.24.2",
|
|
18
18
|
"classnames": "^2.5.1",
|
|
19
|
-
"react": "^19.1.
|
|
20
|
-
"@open-pioneer/core": "4.1.0-dev.
|
|
19
|
+
"react": "^19.1.1",
|
|
20
|
+
"@open-pioneer/core": "4.1.0-dev.20250818125237"
|
|
21
21
|
},
|
|
22
22
|
"exports": {
|
|
23
23
|
"./package.json": "./package.json",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport classNames from \"classnames\";\nimport { HTMLAttributes } from \"react\";\n\n/**\n * Common properties supported by all public react components.\n */\nexport interface CommonComponentProps {\n /**\n * Additional class name(s).\n */\n \"className\"?: string;\n\n /**\n * Used for testing.\n */\n \"data-testid\"?: string;\n}\n\n/**\n * A helper hook that computes react properties for the topmost container in a public react component.\n *\n * Example:\n *\n * ```jsx\n * function MyComponent(props) {\n * const { containerProps } = useCommonComponentProps(\"my-component\", props);\n * // automatically applies css classes and testid\n * return <Box {...containerProps}>Content</Box>;\n * }\n * ```\n */\nexport function useCommonComponentProps(\n componentClassName: string,\n props: CommonComponentProps\n): { containerProps: HTMLAttributes<HTMLElement> } {\n const containerProps = {\n \"className\": classNames(componentClassName, props.className),\n \"data-testid\": props[\"data-testid\"]\n };\n return {\n containerProps\n };\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport classNames from \"classnames\";\nimport { HTMLAttributes } from \"react\";\n\n/**\n * Common properties supported by all public react components.\n */\nexport interface CommonComponentProps {\n /**\n * Additional class name(s).\n */\n \"className\"?: string;\n\n /**\n * Used for testing.\n */\n \"data-testid\"?: string;\n}\n\n/**\n * A helper hook that computes react properties for the topmost container in a public react component.\n *\n * Example:\n *\n * ```jsx\n * function MyComponent(props) {\n * const { containerProps } = useCommonComponentProps(\"my-component\", props);\n * // automatically applies css classes and testid\n * return <Box {...containerProps}>Content</Box>;\n * }\n * ```\n */\nexport function useCommonComponentProps(\n componentClassName: string,\n props: CommonComponentProps\n): { containerProps: HTMLAttributes<HTMLElement> } {\n const containerProps = {\n \"className\": classNames(componentClassName, props.className),\n \"data-testid\": props[\"data-testid\"]\n };\n return {\n containerProps\n };\n}\n"],"names":[],"mappings":";;AAiCO,SAAS,uBAAA,CACZ,oBACA,KAAA,EAC+C;AAC/C,EAAA,MAAM,cAAA,GAAiB;AAAA,IACnB,WAAA,EAAa,UAAA,CAAW,kBAAA,EAAoB,KAAA,CAAM,SAAS,CAAA;AAAA,IAC3D,aAAA,EAAe,MAAM,aAAa;AAAA,GACtC;AACA,EAAA,OAAO;AAAA,IACH;AAAA,GACJ;AACJ;;;;"}
|
package/useEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler | null>(null);\n\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n const stableHandler = useCallback((...args: Args): Ret => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n }, []);\n return stableHandler;\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,SACZ,
|
|
1
|
+
{"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler | null>(null);\n\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n const stableHandler = useCallback((...args: Args): Ret => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n }, []);\n return stableHandler;\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,SACZ,OAAA,EACc;AACd,EAAA,MAAM,UAAA,GAAa,OAA8B,IAAI,CAAA;AAErD,EAAA,eAAA,CAAgB,MAAM;AAClB,IAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAAA,EACzB,CAAC,CAAA;AAED,EAAA,MAAM,aAAA,GAAgB,WAAA,CAAY,CAAA,GAAI,IAAA,KAAoB;AAEtD,IAAA,MAAM,iBAAiB,UAAA,CAAW,OAAA;AAClC,IAAA,OAAO,cAAA,CAAe,GAAG,IAAI,CAAA;AAAA,EACjC,CAAA,EAAG,EAAE,CAAA;AACL,EAAA,OAAO,aAAA;AACX;;;;"}
|