• Latest
  • Trending
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

6 Tools for Debugging React Native — SitePoint

2 months ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Weekly WordPress News: WordPress 5.3.1 Released with Security/Bug Fixes

1 day ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

News – WordPress 5.3.1 Security and Maintenance Release – WordPress.org

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

A New Build of the WooCommerce Admin Plugin

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Welcome Rymera and WholeSale Suite to WPBeginner Growth Fund

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

How To Get Feedback From Your Visitors

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Best eCommerce Fulfillment Options and Companies for Your Store

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Is It Really All That Good? (2019)

2 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

How to Add a Preloader Animation to WordPress (Step by Step)

3 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Twenty Twenty — The WordPress.com Blog

4 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

New Minimum Requirements of WordPress and PHP

4 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

How to Monitor Your WordPress Website Server Uptime (Easy Way)

4 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Keep Your WooCommerce Store Up and Running with WP Buffs

4 days ago
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
  • Home
  • Sources
    • BobWP
    • Chris Lema
    • Colorlib
    • Winning WP
    • WP Beginner
    • WP Explorer
    • WP Lift
    • WP Sessions
    • WP Tavern
    • WP-Com
    • WP-Org
    • WPEka
    • WPMU Dev
    • OnlineRockersHub
  • Top
  • Themes
  • Plugins
  • WooCommerce
  • Free Stuff
  • Popular Tags
    • WordPress
    • Website
    • Templates
    • Tavern
    • SitePoint
  • Videos
No Result
View All Result
  • Home
  • Sources
    • BobWP
    • Chris Lema
    • Colorlib
    • Winning WP
    • WP Beginner
    • WP Explorer
    • WP Lift
    • WP Sessions
    • WP Tavern
    • WP-Com
    • WP-Org
    • WPEka
    • WPMU Dev
    • OnlineRockersHub
  • Top
  • Themes
  • Plugins
  • WooCommerce
  • Free Stuff
  • Popular Tags
    • WordPress
    • Website
    • Templates
    • Tavern
    • SitePoint
  • Videos
No Result
View All Result
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
No Result
View All Result

6 Tools for Debugging React Native — SitePoint

October 29, 2019
in Site Point
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
0
SHARES
1
VIEWS
Share on FacebookShare on Twitter

Debugging is an essential part of software development. It’s through debugging that we know what’s wrong and what’s right, what works and what doesn’t. Debugging provides the opportunity to assess our code and fix problems before they’re pushed to production.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

In the React Native world, debugging may be done in different ways and with different tools, since React Native is composed of different environments (iOS and Android), which means there’s an assortment of problems and a variety of tools needed for debugging.

Thanks to the large number of contributors to the React Native ecosystem, many debugging tools are available. In this brief guide, we’ll explore the most commonly used of them, starting with the Developer Menu.

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. — Brian W. Kernighan

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

The in-app developer menu is your first gate for debugging React Native, it has many options which we can use to do different things. Let’s break down each option.

  • Reload: reloads the app
  • Debug JS Remotely: opens a channel to a JavaScript debugger
  • Enable Live Reload: makes the app reload automatically on clicking Save
  • Enable Hot Reloading: watches for changes accrued in a changed file
  • Toggle Inspector: toggles an inspector interface, which allows us to inspect any UI element on the screen and its properties, and presents and interface that has other tabs like networking, which shows us the HTTP calls, and a tab for performance.

YellowBoxes and RedBoxes

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

RedBoxes are used to display errors. Every time an app throws an error, it will display a RedBox and the description of the error. You can display it any time by writing console.error. But it doesn’t work in the production, meaning that if an error happens in that environment, the app will crash and stop running.

The RedBox is your friend. One of the helpful things about it is that it displays the error and gives you the suggestions on how to fix it, which you won’t find in the console. For example, I’ll frequently write a style property that’s not supported by React Native, or a property that’s used for a specific element—such as setting backroundImage for the View element. The Redbox will throw an error, but it will also show the list of supported style properties that you can apply to the View.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

YellowBoxes are used to display warnings. You can disable them by adding line of code shown below inside index.js in the root directory of your app. But that’s not recommended, as YellowBoxes are very useful. They warn you about things like performance issues and deprecated code. You can use the YellowBox element from react-native to display a specific warning.

import {YellowBox} from 'react-native';
YellowBox.ignoreWarnings(['Warning: ...']);

Most YellowBox warnings are related to some bad practice in your code. For example, you might get a warning that you have an eventListener that you aren’t removing when the component unmounts, or that you have deprecated features and dependencies like this:

warning: ViewPagerAndroid has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/viewpager' instead of 'react-native'. See https://github.com/react-native-community/react-native-viewpager

Fixing these issues will prevent many bugs and will improve the quality of your code.

You can always learn more about debugging React Native in the official docs.

Chrome is possibly the first tool you’d think of for debugging React Native. It’s common to use Chrome’s DevTools to debug web apps, but we can also use them to debug React Native since it’s powered by JavaScript.

To use Chrome’s DevTools with React Native, first make sure you’re connected to the same Wi-Fi, then press command + R if you’re using macOS, or Ctrl + M on Windows/Linux. When the developer menu appears, choose Debug Js Remotely. This will open the default JS debugger.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Then check this address http://localhost:8081/debugger-ui/ in Chrome. You should see this page:

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

You may have to do some troubleshooting on Android.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

To solve this problem, make sure your your machine and the device are connected on the same Wi-Fi, and then add android:usesCleartextTraffic="true" to android/app/src/main/AndroidManifest.xml. If this doesn’t work for you, check out these links for other solutions:

After you have successfully connected to Chrome, you can simply toggle the Chrome inspector.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Then take a look at the logs of your React Native app. Also have a look through the other features offered by Chrome’s DevTools, and use them with React Native as you do with any Web app.

One of the limitations of using Chrome’s DevTools with React Native is that you can’t debug the styles and edit the style properties as you usually do when you debug web apps. It’s also limited in comparison with React’s devtools when inspecting React’s component hierarchy.

To debug React Native using React’s Developer Tools, you need to use the desktop app. You can install it globally or locally in your project by just running this following command:

yarn add react-devtools

Or npm:

npm install react-devtools --save

Then start the app by running yarn react-devtools, which will launch the app.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

React’s Developer Tools may be the best tool for debugging React Native for these two reasons:

  • It allows for debugging React components.
  • It makes it possible to debug styles in React Native (my favorite feature of these developer tools!). The new version comes with this feature that also works with inspector in the developer menu. Previously, it was a problem to write styles and have to wait for the app to reload to see the changes. Now we can debug and implement style properties and see the effect of the change instantly without reloading the app.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

You can learn more about using React’s Developer Tools app here.

React Native Debugger

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

If you’re using Redux in your React Native app, React Native Debugger is probably the right debugger for you. It’s a standalone desktop app that works on macOS, Windows, and Linux. It integrates both Redux’s DevTools and React’s Developer Tools in one app so you don’t have to work with two separate apps for debugging.

React Native Debugger is my favorite debugger and the one I usually use in my work with React Native. It has an interface for Redux’s DevTools where you can see the Redux logs and the actions, and an interface for React’s Developer Tools where you can inspect and debug React elements. You can find the installation instructions here. You can connect with this debugger in the same way you open Chrome’s inspector.

Using React Native Debugger over Chrome’s DevTools has some advantages. For example, you can toggle the inspector from the Dev Menu to inspect React Native elements and edit styles, which isn’t available in Chrome’s DevTools.

React Native CLI

You can use the React Native CLI to do some debugging as well. You can use it for showing the logs of the app. Hitting react-native log-android will show you the logs of db logcat on Android, and to view the logs in iOS you can run react-native log-ios, and with console.log you can dispatch logs to the terminal:

console.log("some error🛑")

You should then see the logs in the terminal.

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

You can use the React Native CLI to get some relevant info about the libraries and the dependencies you’re using in your app, by running react-native info on the terminal. It shows us some useful info about the tools you’re using. For instance, here’s an example of an output when you run react-native info:

, 6 Tools for Debugging React Native — SitePoint, Rojak WP

You can use this info to fix some bugs caused by version mismatches of a tool you’re using in your project, so it’s always good to check the environment info using this command.

Summary

There are lots of tools for debugging React Native in addition to the ones we’ve looked at here. It really depends on the specific needs of your project. I mostly use React Native Debugger Desktop because I often work with Redux, and it combines an array of tools in one app which is great and a time saving.

Please hit me on Twitter if you’d like to talk more about tools to debug React Native and about React Native in general. I’d love to hear from you!


, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Said is an NYC-based front-end developer, technical writer and instructor.



Credited Source

Tags: DebuggingNativeReactSitePointTools
Previous Post

Why Your Agency Should Offer Managed Cloud Hosting to Clients — SitePoint

Next Post

Not Attending WordCamp US 2019? How to Watch From Home – WordPress Tavern

Related Posts

, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

How to Divert Traffic Using IP2Location in a Next.js Website — SitePoint

December 5, 2019
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

Configuration, Customization & Usage — SitePoint

December 4, 2019
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

Building a Habit Tracker with Prisma 2, Chakra UI, and React — SitePoint

December 3, 2019
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

Black Friday 2019 for Designers and Developers — SitePoint

November 30, 2019
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

Delay, Sleep, Pause, & Wait in JavaScript — SitePoint

November 28, 2019
, 6 Tools for Debugging React Native — SitePoint, Rojak WP
Site Point

Understanding module.exports and exports in Node.js

November 27, 2019
Next Post
, 6 Tools for Debugging React Native — SitePoint, Rojak WP

Not Attending WordCamp US 2019? How to Watch From Home – WordPress Tavern

Ads

Rojak WP © 2019

No Result
View All Result
  • Home
  • Sources
    • BobWP
    • Chris Lema
    • Colorlib
    • Winning WP
    • WP Beginner
    • WP Explorer
    • WP Lift
    • WP Sessions
    • WP Tavern
    • WP-Com
    • WP-Org
    • WPEka
    • WPMU Dev
    • OnlineRockersHub
  • Top
  • Themes
  • Plugins
  • WooCommerce
  • Free Stuff
  • Popular Tags
    • WordPress
    • Website
    • Templates
    • Tavern
    • SitePoint
  • Videos

Rojak WP © 2019