What are error boundaries and how do you use them?

React 19 and architecture · Freshers and experienced

Model answer

An error boundary catches errors thrown while rendering its children and shows a fallback UI instead of crashing the whole app. It is a class component with getDerivedStateFromError and componentDidCatch, or you can use a library such as react-error-boundary.

It does not catch errors in event handlers or async code, so handle those with try/catch.

Learn this topic

React 19 New Features: Actions, useActionState, useOptimistic, use and More in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions