Solomon Eseme I am a software developer who is geared toward building high-performing and innovative products following best practices and industry standards. I also love writing about it at masteringbackend.com. Follow me on Twitter @kaperskyguru, on Facebook, onLinkedIn, and on About.Me at Solomon Eseme." Follow me: Twitter, Facebook, LinkedIn, about.me

Intro to LogBox, React Native’s new and improved debugging experience

1 min read 473

Intro to LogBox, React Native's New and Improved Debugging Experience

On July 6, React Native announced that a new version of React Native 0.63 would be shipped with LogBox and turned on by default. Prior to this release, the community had raised concerns about errors and warnings that were difficult to debug. The React Native team responded by redesigning the entire error, warnings, and logging system from the ground up.

In this guide, we’ll go over the basics and walk you through how to use LogBox.

Prerequisites

  1. Basic knowledge of React
  2. Basic knowledge of React Native

What is LogBox?

If you’ve ever experienced the hideous red or yellow box in React Native, you’ll understand why something had to be done. To improve velocity and the overall developer experience, the React Native team introduced the LogBox, which offers a completely redesigned logging experience.

LogBox addresses complaints that errors and warnings in React Native were too verbose, poorly formatted, and unactionable. The new solution is:

  1. Concise — logs should only provide information necessary for debugging processes
  2. Formatted — logs should be formatted in such a way that it’s easy and faster to find relevant information
  3. Actionable — logs should be clickable/actionable, so you can go straight to the line where the error is happening.

LogBox is also a complete improvement of the visual design that’s consistent between errors and warnings.

How to use LogBox

In React Native 0.63, LogBox is turned on by default, no configuration needed. If you’re using an older version, you can enable LogBox by importing React Native.

require('react-native').unstable_enableLogBox();

If you run into any errors while you’re coding, LogBox will pop out like this automatically:

Component Exception Error in LogBox

Similarly, when you encounter warnings in your source codes, the new yellow box will display.

VirtualizedList Warning in LogBox

Building a simple React Native 0.63 Application

To show you LogBox in action, we’ll build a simple application in React Native 0.63.

Installation

If you’re just starting out with React Native, you might want to read this guide to setting up the development environment.

Creating your React Native app

After successful installation and configuration, run the following commands to create a new React Native project.

expo init todos-native
cd todos-native
npm start

Make sure you install the current version, React Native 0.63.

If you want, you can simply clone this React Native app by AndrewMorsillo.

Implementations and errors

For the purpose of this tutorial, we’ll simply modify the App.js file to display a list of information on the screen and introduce error and warning functions.

 

Testing the buggy app

The application should reload automatically once you save your changes. Below we’re presented with the newly and nicely redesigned yellow box.

Useless Stack Warning in LogBox

Conclusion

In this article, we reviewed the new features of React Native. We also showed how the team completely redesigned the logging functionality to improve the developer experience and boost velocity.



Happy debugging!

LogRocket: Instantly recreate issues in your React Native apps.

LogRocket is a React Native monitoring solution that helps you reproduce issues instantly, prioritize bugs, and understand performance in your React Native apps.

LogRocket also helps you increase conversion rates and product usage by showing you exactly how users are interacting with your app. LogRocket's product analytics features surface the reasons why users don't complete a particular flow or don't adopt a new feature.

Start proactively monitoring your React Native apps — .

Solomon Eseme I am a software developer who is geared toward building high-performing and innovative products following best practices and industry standards. I also love writing about it at masteringbackend.com. Follow me on Twitter @kaperskyguru, on Facebook, onLinkedIn, and on About.Me at Solomon Eseme." Follow me: Twitter, Facebook, LinkedIn, about.me

Leave a Reply