forked from alan2207/bulletproof-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
53 lines (49 loc) · 1.64 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as React from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { HelmetProvider } from 'react-helmet-async';
import { QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
import { BrowserRouter as Router } from 'react-router-dom';
import { Button, Spinner } from '@/components/Elements';
import { Notifications } from '@/components/Notifications/Notifications';
import { AuthProvider } from '@/lib/auth';
import { queryClient } from '@/lib/react-query';
const ErrorFallback = () => {
return (
<div
className="text-red-500 w-screen h-screen flex flex-col justify-center items-center"
role="alert"
>
<h2 className="text-lg font-semibold">Ooops, something went wrong :( </h2>
<Button className="mt-4" onClick={() => window.location.assign(window.location.origin)}>
Refresh
</Button>
</div>
);
};
type AppProviderProps = {
children: React.ReactNode;
};
export const AppProvider = ({ children }: AppProviderProps) => {
return (
<React.Suspense
fallback={
<div className="flex items-center justify-center w-screen h-screen">
<Spinner size="xl" />
</div>
}
>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<HelmetProvider>
<QueryClientProvider client={queryClient}>
{process.env.NODE_ENV !== 'test' && <ReactQueryDevtools />}
<Notifications />
<AuthProvider>
<Router>{children}</Router>
</AuthProvider>
</QueryClientProvider>
</HelmetProvider>
</ErrorBoundary>
</React.Suspense>
);
};