Skip to content
Merged
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
15 changes: 12 additions & 3 deletions src/hooks/useId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import * as React from 'react';

function getUseId() {
// We need fully clone React function here to avoid webpack warning React 17 do not export `useId`
const fullClone = {
...React,
};

return fullClone.useId;
}

let uuid = 0;

/** @private Note only worked in develop env. Not work in production. */
Expand All @@ -13,11 +22,11 @@ export default function useId(id?: string) {
// Inner id for accessibility usage. Only work in client side
const [innerId, setInnerId] = React.useState<string>('ssr-id');

// eslint-disable-next-line react-hooks/rules-of-hooks
const reactNativeId = React.useId?.();
const useOriginId = getUseId();
const reactNativeId = useOriginId?.();

React.useEffect(() => {
if (!React.useId) {
if (!useOriginId) {
const nextId = uuid;
uuid += 1;

Expand Down