mirror of
https://github.com/oiov/wr.do.git
synced 2026-05-18 12:16:29 +08:00
32 lines
581 B
TypeScript
32 lines
581 B
TypeScript
"use client";
|
|
|
|
import { Component, ReactNode } from "react";
|
|
|
|
// 错误边界组件(客户端组件)
|
|
interface ErrorBoundaryProps {
|
|
fallback: ReactNode;
|
|
children: ReactNode;
|
|
}
|
|
|
|
interface ErrorBoundaryState {
|
|
hasError: boolean;
|
|
}
|
|
|
|
export class ErrorBoundary extends Component<
|
|
ErrorBoundaryProps,
|
|
ErrorBoundaryState
|
|
> {
|
|
state: ErrorBoundaryState = { hasError: false };
|
|
|
|
static getDerivedStateFromError() {
|
|
return { hasError: true };
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return this.props.fallback;
|
|
}
|
|
return this.props.children;
|
|
}
|
|
}
|