error boundary

This commit is contained in:
2024-05-04 15:33:31 +03:00
parent bae7e17444
commit c70b0e7236
4 changed files with 71 additions and 40 deletions

View File

@@ -0,0 +1,21 @@
import React from 'react'
export class ErrorBoundary extends React.Component {
state = {
error: false
}
static getDerivedStateFromError() {
return {
error: true
}
}
render() {
if (this.state.error) {
return <h1>Something went wrong.</h1>
}
return this.props.children
}
}