feat: add error boundary

makes crashes graceful
This commit is contained in:
zyachel
2023-01-22 21:14:46 +05:30
parent 71d1d5b34e
commit 5cc2ef02ce
7 changed files with 104 additions and 28 deletions

View File

@@ -1,10 +1,10 @@
import type { AppProps } from 'next/app';
import usePageLoading from '../hooks/usePageLoading';
import ProgressBar from '../components/loaders/ProgressBar';
import ErrorBoundary from '../components/error/ErrorBoundary';
import ThemeProvider from '../context/theme-context';
import '../styles/main.scss';
import { useRouter } from 'next/router';
const ModifiedApp = ({ Component, pageProps }: AppProps) => {
const { isPageLoading, key } = usePageLoading();
@@ -12,10 +12,12 @@ const ModifiedApp = ({ Component, pageProps }: AppProps) => {
return (
<ThemeProvider>
{isPageLoading && <ProgressBar />}
<Component
{...pageProps}
key={key} /* passing key to force react to remound components */
/>
<ErrorBoundary>
<Component
{...pageProps}
key={key} /* passing key to force react to remount components */
/>
</ErrorBoundary>
</ThemeProvider>
);
};