0

When trying to debug React Native within the web browser, I am unable to see any Component names. Whether via standard browser DevTools or the React (Component) browser extension, I do not see any reference to the Component names or even the classNames.

Component names are obfuscated by View, Anonymous, Screen, etc in the React extension. Part of that how the code is written using React Native's defaultView and Screen components. But I would expect to see the child components nested eventually.

enter image description here

CSS classes are in css-xyz123 format, seemingly unrelated to their actual Component and class names.

enter image description here

Anyone know why this is occurring or how to get the Component names visible for web debugging? I considered a few causes:

  • How the components are written (functional components, often wrapped with Mobx observers)
  • Babel compiler settings
  • Other minifiction or React Native build settings

Thank you!

1 Answer 1

1

A component name like "Anonymous (ForwardRef)" means your source code probably looks something like this:

const Component = React.forwardRef((props, ref) => {...});

The function passed to forwardRef is an anonymous function, so there is no name for DevTools to read. (Note that this will also be true for built-in browser tooling.)

To "fix" this, you can use a named function. There are two options:

const Component = React.forwardRef(function MyComponent(props, ref) {...});

Or:

const MyComponent = (props, ref) => {...};
const Component = React.forwardRef(MyComponent);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply and suggestions, @bvaughn! I love the idea about forwardRef & anonymous functions. Unfortunately, that const Component = React.forwardRef does not seem to be the culprit as I am not using forwardRef. For reference, here are a few examples of component declaration structures I'm using often. Ex 1, Mobx observerexport const MyComponentMemo = observer(function MyComponentMemo_({ etc }: MyComponentProps) { Ex 2, export const MyListView = ({ sort }: MyListViewProps) => { Ex 3, export const MyComponent = ({ prop1, prop2 }: MyComponentProps) => {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.