Files
tech-log-frontend/src/features/tech-log/presentation/studio/studio-runtime-boundary.tsx
T

47 lines
1.4 KiB
TypeScript

import { Component, Fragment, type ReactNode } from "react";
export class StudioRuntimeBoundary extends Component<
Readonly<{ children: ReactNode }>,
Readonly<{ failed: boolean; resetKey: number }>
> {
state = { failed: false, resetKey: 0 };
static getDerivedStateFromError() {
return { failed: true };
}
private retry = () => {
this.setState((current) => ({
failed: false,
resetKey: current.resetKey + 1,
}));
};
render() {
if (this.state.failed) {
return (
<div className="studio-app">
<header className="studio-header">
<div className="studio-header-inner">
<a className="studio-wordmark" href="/studio">
TechLog <span>Studio</span>
</a>
</div>
</header>
<main id="main-content" className="studio-main">
<section className="studio-route-state" role="alert">
<p className="studio-eyebrow">STUDIO ERROR</p>
<h1>Studio 화면을 불러오지 못했습니다</h1>
<p>현재 세션을 초기화한 뒤 다시 시작하세요.</p>
<button type="button" onClick={this.retry}>
다시 시작
</button>
</section>
</main>
</div>
);
}
return <Fragment key={this.state.resetKey}>{this.props.children}</Fragment>;
}
}