We use cookies to enhance your browsing experience.

Learn More
Back to Library
REACTjavascript

Error Boundary

Catch errors in child component tree.

class ErrorBoundary extends React.Component {
  state = { hasError: false };
  static getDerivedStateFromError(error) {
    return { hasError: true };
  }
  render() {
    if (this.state.hasError) return <h1>Something went wrong.</h1>;
    return this.props.children;
  }
}
react error component
25+Total Tools
Operations
4Languages
100%Privacy

We use cookies to enhance your experience and serve personalized ads.