'use client'; /* ════════════════════════════ ErrorBoundary ════════════════════════════ * Vangt render crashes op en toont een fallback UI i.p.v. een lege pagina. */ import { Component, type ReactNode, type ErrorInfo } from 'react'; import { AlertCircle, RefreshCw } from 'lucide-react'; interface Props { children: ReactNode; fallback?: ReactNode; /** Optional: label om te tonen welk onderdeel crashed */ label?: string; } interface State { error: Error | null; info: ErrorInfo | null; } export default class ErrorBoundary extends Component { state: State = { error: null, info: null }; static getDerivedStateFromError(error: Error) { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error(`[ErrorBoundary${this.props.label ? ` ${this.props.label}` : ''}]`, error, info); this.setState({ info }); } handleRetry = () => { this.setState({ error: null, info: null }); }; render() { if (this.state.error) { if (this.props.fallback) return this.props.fallback; return (

{this.props.label ? `Fout in ${this.props.label}` : 'Er ging iets mis'}

{this.state.error.message || 'Onbekende fout'}

); } return this.props.children; } }