Skip to content

Commit d594e9b

Browse files
authored
fix(useid): guard against useId not being exported (#14153)
1 parent 63cf8ee commit d594e9b

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

packages/react/src/internal/useId.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@
2828
// the new hook and call the `nativeReactUseid` function, but if the user is
2929
// running a version older than React 18 we will keep using our old hook.
3030

31-
import {
32-
useEffect,
33-
useLayoutEffect,
34-
useState,
35-
useId as reactUseId,
36-
} from 'react';
31+
import React, { useEffect, useLayoutEffect, useState } from 'react';
3732
import setupGetInstanceId from '../tools/setupGetInstanceId';
3833
import { canUseDOM } from './environment';
3934
import { useIdPrefix } from './useIdPrefix';
@@ -70,7 +65,7 @@ export function useId(prefix = 'id') {
7065
}
7166
}, []);
7267

73-
if (reactUseId) {
68+
if (typeof React['useId'] === 'function') {
7469
const id = nativeReactUseId(_prefix, prefix);
7570
return id;
7671
}
@@ -79,7 +74,7 @@ export function useId(prefix = 'id') {
7974
}
8075

8176
function nativeReactUseId(_prefix, prefix) {
82-
const getId = reactUseId();
77+
const getId = React['useId']();
8378

8479
const id = `${_prefix ? `${_prefix}-` : ``}${prefix}-${getId}`;
8580

0 commit comments

Comments
 (0)