Error Handling in React JS

We can divide errors generally into 2 varieties, and error handling into 2 aspects.

The two error types:

1. JavaScript errors

2. Render errors

The two aspects of error handling:

1. Displaying data to the user

2. Providing data to the developer

React error boundaries

getDerivedStateFromError

Listing 1. getDerivedStateFromError()

componentDidCatch

Listing 2. componentDidCatch

Rendering based on error

Listing 3. ErrorBoundary rendering

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store