Error Handling

Let's catch some errors in your application and debug them!

We'll cover the following

In this lesson, we introduce an efficient solution to add error handling for the application that we are building in case of an erroneous API request. We must know the necessary building block to introduce error handling in React: local state and conditional rendering. The error is just another state, which we store in the local state and display with conditional rendering in the component.

Now, we’ll implement it in the App component, since that’s where we fetch data from the Hacker News API. First, introduce the error in the local state. It is initialized as null but will be set to the error object in case of an error.

Get hands-on with 1400+ tech skills courses.