Initial commit
This commit is contained in:
35
resources/js/components/AppErrorBoundary.tsx
Normal file
35
resources/js/components/AppErrorBoundary.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from "react";
|
||||
|
||||
type AppErrorBoundaryProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
type AppErrorBoundaryState = {
|
||||
hasError: boolean;
|
||||
};
|
||||
|
||||
export default class AppErrorBoundary extends React.Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
|
||||
state: AppErrorBoundaryState = {
|
||||
hasError: false,
|
||||
};
|
||||
|
||||
static getDerivedStateFromError() {
|
||||
return { hasError: true };
|
||||
}
|
||||
|
||||
componentDidCatch(error: unknown, info: React.ErrorInfo) {
|
||||
console.error("AppErrorBoundary caught an error", error, info);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div className="p-4 text-sm text-red-600">
|
||||
Došlo k chybě při vykreslování stránky.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user