mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: rebuild app using vike
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import React from "react";
|
||||
|
||||
type ErrorBoundaryProps = {
|
||||
fallback?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
type ErrorBoundaryState = {
|
||||
error?: Error | null;
|
||||
};
|
||||
|
||||
class ErrorBoundary extends React.Component<
|
||||
ErrorBoundaryProps,
|
||||
ErrorBoundaryState
|
||||
> {
|
||||
constructor(props: ErrorBoundaryProps) {
|
||||
super(props);
|
||||
this.state = { error: null };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error: unknown) {
|
||||
return { error };
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children, fallback } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
if (!fallback) {
|
||||
return (
|
||||
<div className="p-4 text-sm">
|
||||
<p>An error occured!</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
||||
Reference in New Issue
Block a user