How do I properly debug in React Native?

gurs1kh

How do I properly debug in React Native? From what I've seen so far, the debugging messages given aren't too useful for narrowing down where to look in my code. I just get a stack trace that only mentions dependencies in node_modules For example:

Android emulator image (sorry, don't have enough reputation to show image on this post)

In the above error, I understsand that somewhere a non-Component object got passed in, but I have no idea how to track it down; the entire stack trace only mentions files from node_modules.

I have tried using Chrome Developer Tools as well:

Chrome Developer Tools image

I have also tried React Developer Tools and it wasn't helpful either.

How do I go about getting output from debugging that is actually helpful and linked to the code that I wrote?

SoZettaSho

Unfortunately the stack trace isn't always helpful since in this case you have to go through the bridge, and there isn't any single catch-all answer to how to get the information you need.

In this case, you're right that you most likely made a mistake returning a proper JSX object in one of your components. If you remember which components you recently added to your app, which components make up the navigator route that led to the problem, etc, you can make an educated guess as to the set of possible problematic components, and narrow that set down by commenting things out. Once that set is a reasonable size, triple-check your render methods and make sure nothing weird is going on.

You can write your own debug messages to the chrome developer console to help give yourself an idea what your app is doing (e.g. rendering this component, fetching that data from shared store, etc) using if(__DEV__) console.log("Your message here"). This will check if the app is running in a debug vs release build, and only log the messages if you are running a debug build.

You can use adb logcat for android and the XCode console for iOS to see the native debug logs, although I don't think they'll help in this case.

You can draw a picture of your component tree, put a debugger statement at the beginning of every render method, and check off components one-by-one until your app stops trying to render things and you know you've hit a problematic component (React will render components recursively, going from top-to-bottom for components on the same level in the tree).

I know it's frustrating when you can't immediately tell where the problem is by glancing at the stack trace but sometimes that's life.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I debug "Objects are not valid as a React child" react native error

From Dev

How do you debug linking errors in React Native iOS?

From Dev

How do you debug react-native in Ubuntu 14.10?

From Dev

How do you debug react-native in Ubuntu 14.10?

From Dev

How do you debug a react-native Universal Windows Application?

From Dev

How can I properly import a Component into my Navigator in React Native?

From Java

How to debug with breakpoints in React Native

From Java

How do I "shake" an Android device within the Android emulator to bring up the dev menu to debug my React Native app

From Dev

How do I enable multidex for react native?

From Dev

In ClojureScript, how do I properly use cljsjs/react-mdl?

From Dev

How do i properly configure debug level and ehcache in a play framework dist?

From Dev

How do i properly configure debug level and ehcache in a play framework dist?

From Dev

How do I debug macros?

From Dev

How do I debug snaps?

From Dev

How do I debug DHCP?

From Dev

How do you debug Java code in React Native Android using console

From Dev

How to properly position a view with AnimatedCircularProgress in React Native

From Dev

How to properly start a detached React Native app

From Java

How can I determine if my React Native app is a debug or release build from JavaScript code?

From Dev

How do you properly emit and receive an event from a bridged iOS module to JavaScript using React Native?

From Dev

How do I set a marker in MapView of React Native

From Java

How do I add an element to array in reducer of React native redux?

From Dev

How do I display an animated gif in React Native?

From Dev

How do I use a captured image with react-native-camera

From Dev

How do I make components in React Native without using JSX?

From Dev

How do I actually use Image.capInsets in React Native?

From Dev

How do I use Crashlytics for my React Native Android App?

From Dev

How do I hide or suppress react-native warning

From Dev

How do I access the phone's camera with React Native iOS?

Related Related

  1. 1

    How do I debug "Objects are not valid as a React child" react native error

  2. 2

    How do you debug linking errors in React Native iOS?

  3. 3

    How do you debug react-native in Ubuntu 14.10?

  4. 4

    How do you debug react-native in Ubuntu 14.10?

  5. 5

    How do you debug a react-native Universal Windows Application?

  6. 6

    How can I properly import a Component into my Navigator in React Native?

  7. 7

    How to debug with breakpoints in React Native

  8. 8

    How do I "shake" an Android device within the Android emulator to bring up the dev menu to debug my React Native app

  9. 9

    How do I enable multidex for react native?

  10. 10

    In ClojureScript, how do I properly use cljsjs/react-mdl?

  11. 11

    How do i properly configure debug level and ehcache in a play framework dist?

  12. 12

    How do i properly configure debug level and ehcache in a play framework dist?

  13. 13

    How do I debug macros?

  14. 14

    How do I debug snaps?

  15. 15

    How do I debug DHCP?

  16. 16

    How do you debug Java code in React Native Android using console

  17. 17

    How to properly position a view with AnimatedCircularProgress in React Native

  18. 18

    How to properly start a detached React Native app

  19. 19

    How can I determine if my React Native app is a debug or release build from JavaScript code?

  20. 20

    How do you properly emit and receive an event from a bridged iOS module to JavaScript using React Native?

  21. 21

    How do I set a marker in MapView of React Native

  22. 22

    How do I add an element to array in reducer of React native redux?

  23. 23

    How do I display an animated gif in React Native?

  24. 24

    How do I use a captured image with react-native-camera

  25. 25

    How do I make components in React Native without using JSX?

  26. 26

    How do I actually use Image.capInsets in React Native?

  27. 27

    How do I use Crashlytics for my React Native Android App?

  28. 28

    How do I hide or suppress react-native warning

  29. 29

    How do I access the phone's camera with React Native iOS?

HotTag

Archive