Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ponyfill useId #85

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/ActionControl/ActionControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ limitations under the License.
*/

import classnames from "classnames";
import React, { PropsWithChildren, useId, forwardRef } from "react";
import React, { PropsWithChildren, forwardRef } from "react";
import styles from "./ActionControl.module.css";

import { Control, Field, Root } from "../Form";
import useId from "../../utils/useId";

type ActionControlProps = {
/**
Expand Down
16 changes: 16 additions & 0 deletions src/utils/useId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from "react";

const react18UseId = (React as { useId?: () => string }).useId;

const getUniqueId = (() => {
let index = 1;
return () => `:r${index++}:`;
})();

const useIdPonyFill = (): string => {
return React.useMemo(getUniqueId, []);
};

const useId = typeof react18UseId === "function" ? react18UseId : useIdPonyFill;

export default useId;
Loading