Skip to content

Commit

Permalink
Ponyfill useId
Browse files Browse the repository at this point in the history
Fixes: #224
  • Loading branch information
Johennes committed Sep 25, 2023
1 parent 0033036 commit 7f75c26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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';

Check failure on line 1 in src/utils/useId.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `'react'` with `"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;

Check failure on line 14 in src/utils/useId.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `(typeof·react18UseId·===·"function")` with `typeof·react18UseId·===·"function"`

export default useId;

0 comments on commit 7f75c26

Please sign in to comment.