41 lines · 1.1 KB · TypeScript
RawDownload
import { Component, type ReactNode } from "react"; interface RenderErrorBoundaryProps {  readonly children: ReactNode;  readonly fallback: ReactNode;  readonly resetKeys?: ReadonlyArray<unknown>;} interface RenderErrorBoundaryState {  readonly failed: boolean;  readonly resetKeys?: ReadonlyArray<unknown> | undefined;} export class RenderErrorBoundary extends Component<  RenderErrorBoundaryProps,  RenderErrorBoundaryState> {  override state = { failed: false, resetKeys: this.props.resetKeys };   // Retry changed inputs without remounting healthy children or their controls.  static getDerivedStateFromProps(    { resetKeys }: RenderErrorBoundaryProps,    state: RenderErrorBoundaryState,  ) {    if (      resetKeys?.length !== state.resetKeys?.length ||      resetKeys?.some((key, index) => !Object.is(key, state.resetKeys?.[index]))    ) {      return { failed: false, resetKeys };    }    return null;  }   static getDerivedStateFromError() {    return { failed: true };  }   override render() {    return this.state.failed ? this.props.fallback : this.props.children;  }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t