Skip to content

Commit

Permalink
fix(react): fallback to React 18 internals for getting component names (
Browse files Browse the repository at this point in the history
  • Loading branch information
bowheart authored Dec 11, 2024
1 parent 09cdac5 commit 3d9d6f7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react/src/hooks/useReactComponentId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const serverKey = `__SERVER${react19KeyBase}` as const
* can at the cost of some DX.
*/
export const useReactComponentId = () => {
const component: MaybeComponent = (
(React as React19)[clientKey] || (React as React19)[serverKey]
)?.A?.getOwner?.()?.type
const component: MaybeComponent =
(
(React as React19)[clientKey] || (React as React19)[serverKey]
)?.A?.getOwner?.()?.type ||
(React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
?.ReactCurrentOwner?.current?.type

const name = component?.displayName || component?.name || 'rc'

Expand Down

0 comments on commit 3d9d6f7

Please sign in to comment.