Replies: 2 comments
-
This can be a hint: pmndrs/zustand#2061 (comment) by @AlexeevSasha |
Beta Was this translation helpful? Give feedback.
0 replies
-
I quite like Zedux's way of capturing the React component name without a stack trace. Basically using React's internal API. Snippet taken from https://github.com/Omnistac/zedux/blob/master/packages/react/src/hooks/useReactComponentId.ts : const react19KeyBase = '_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE';
const clientKey = `__CLIENT${react19KeyBase}` as const;
const serverKey = `__SERVER${react19KeyBase}` as const;
export function useReactComponentId() {
const component: MaybeComponent =
((React as React19)[clientKey] ?? (React as React19)[serverKey])?.A?.getOwner?.().type ??
(React as React18).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current?.type;
const name = component?.displayName || component?.name || 'unknown';
const id = useId();
return `${name}-${id}`;
} Cons :
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Moved from pmndrs/jotai#931
Experimental PR: pmndrs/jotai#943
If we do something, it will be
jotai
, not onlyjotai-devtools
, but this should be a good place for discussion.Beta Was this translation helpful? Give feedback.
All reactions