Replies: 3 comments
-
|
This can be a hint: pmndrs/zustand#2061 (comment) by @AlexeevSasha |
Beta Was this translation helpful? Give feedback.
-
|
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.
-
|
Good news, React 19.1 introduced captureOwnerStack : an API to retrieve the list of parent components. I've been toying with it a bit and released an experimental API for jotai-logger today using both Instead of trying to parse error strack traces ourselves, this is much more stable. |
Beta Was this translation helpful? Give feedback.
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