Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
import React, { ReactNode, ReactElement } from 'react'
type ErrorBoundaryProps = {
children: ReactNode
renderFallbackComponent: (props: { error?: unknown }) => ReactElement
}
type ErrorBoundaryState = { error: null | unknown }
export default class ErrorBoundary extends React.Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
constructor(props: ErrorBoundaryProps) {
super(props)
this.state = { error: null }
}
static getDerivedStateFromError(error: unknown) {
return { error }
}
render() {
if (this.state.error) {
return this.props.renderFallbackComponent({ error: this.state.error })
}
return this.props.children
}
}