Skip to content

Instantly share code, notes, and snippets.

@esemeniuc
esemeniuc / ErrorBoundary.tsx
Last active June 29, 2023 14:40
ErrorBoundary for React 16 using Typescript
import React, {ErrorInfo} from 'react';
export default class ErrorBoundary extends React.Component<{}, { hasError: boolean }> {
constructor(props: {}) {
super(props);
this.state = {hasError: false};
}
static getDerivedStateFromError(error: Error) { // Update state so the next render will show the fallback UI.
return {hasError: true};