Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View component hierarchy in React Native

When debugging a React website, I can view the component hierarchy using the React Developer Tools:

picture of React devtools

How can I do the same in React Native? The rage shake menu contains an 'inspector' but it only seems to let me inspect a single element by tapping it - I don't see any way to browse the full component hierarchy.

like image 843
Mark Amery Avatar asked Nov 26 '15 12:11

Mark Amery


People also ask

What is component hierarchy in React?

We create a tree-like diagram called component hierarchy. This gives us information about the parent-child relationship between components, tells us about which component renders other components and helps us to organize the overall state of the application.

How do you show and hide view in React Native?

This is an Example to Hide Show Component in React Native. To do this we will use a conditional operator and state. When we change the state view will re-render itself and after checking the state we will return the view or null. In this example, we are hiding and showing the image on a click of a button.

What is testID in React Native?

React-Native supports an attribute called testID for Views. Through Appium, this testID attribute is exposed directly as "name" when working with iOS. In those cases, the value of the testID set in React-Native will be shown directly under the name attribute eg. in the ObjectSpy.


2 Answers

Unfortunately, since version 0.12 of react-native, the Devtools "React" Tab does not work anymore. It's a known issue.

There's a quite active discussion on Github that has been open for a while, but no solutions yet.

UPDATE

The Devtools "React" tab still don't work in Chrome, but the latest Nuclide has it built in! (It's an IDE built on top of Atom).

With Atom installed with the Nuclide package, start your app and deactivate chrome or safari debugging.

Then, pressing Cmd+Shift+P in Atom will trigger the command palette and you can toggle the dev tools by searching for React Native Inspector:

Inspector

like image 146
Almouro Avatar answered Oct 22 '22 12:10

Almouro


This works for me using the standalone react-devtools app with React Native 0.55.

  1. Run npm install -g react-devtools
  2. Run react-devtools
  3. Open React Native app and select "Start Remote JS Debugging" from dev menu
like image 21
Eliot Avatar answered Oct 22 '22 13:10

Eliot