import React, { ErrorInfo, ReactNode } from 'react' import { persister, queryClient } from '../queryClient' import './ErrorBoundary.css' interface Props { children: ReactNode } interface State { hasError: boolean error: Error | null showDetails: boolean } export class ErrorBoundary extends React.Component { state: State = { hasError: false, error: null, showDetails: false, } static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error } } componentDidCatch(error: Error, info: ErrorInfo) { console.error(error, info) } toggleDetails = () => { this.setState(({ showDetails }) => ({ showDetails: !showDetails })) } reloadPage = async () => { queryClient.clear() await persister.removeClient() window.location.reload() } render() { const { hasError, error, showDetails } = this.state if (hasError) { return (
Something went wrong
Try clearing cache and refreshing. If that fails, reveal the error details below and report them on{' '} GitHub. {' '} Consider removing sensitive info (like IP or URL) before sharing.
                            {error?.stack || error?.toString()}
                        
Jelly Music App - Version {__VERSION__}
) } return this.props.children } }