Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

895 B
Raw Blame
import { Button } from '@lobehub/ui';
import { Component, type PropsWithChildren } from 'react';

interface PanelErrorBoundaryState {
  error?: Error;
}

class PanelErrorBoundary extends Component<PropsWithChildren, PanelErrorBoundaryState> {
  state: PanelErrorBoundaryState = {};

  static getDerivedStateFromError(error: Error): PanelErrorBoundaryState {
    return { error };
  }

  render() {
    if (!this.state.error) return this.props.children;
    return (
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8, padding: 16 }}>
        <span style={{ fontSize: 12 }}>Panel crashed: {this.state.error.message}</span>
        <Button
          size={'small'}
          style={{ alignSelf: 'flex-start' }}
          onClick={() => this.setState({ error: undefined })}
        >
          Retry
        </Button>
      </div>
    );
  }
}

export default PanelErrorBoundary;