mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Errors in form actions are now rethrown during render (#26689), so we can handle them using an error boundary.
17 lines
355 B
JavaScript
17 lines
355 B
JavaScript
'use client';
|
|
|
|
import * as React from 'react';
|
|
|
|
export default class ErrorBoundary extends React.Component {
|
|
state = {error: null};
|
|
static getDerivedStateFromError(error) {
|
|
return {error};
|
|
}
|
|
render() {
|
|
if (this.state.error) {
|
|
return <div>Caught an error: {this.state.error.message}</div>;
|
|
}
|
|
return this.props.children;
|
|
}
|
|
}
|