aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-10-12 13:36:01 +0100
committerGravatar Joe Banks <[email protected]>2020-10-12 13:36:01 +0100
commit259b9bb0eb5e35f902413fe4c6c4175b46e50005 (patch)
tree887ab8828981665fb51bb4c50fc0cf43a96bba62 /src
parentUpdate app with new build system (diff)
Lazy load components
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/App.tsx b/src/App.tsx
index 19ba6a6..56aff08 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,5 +1,6 @@
/** @jsx jsx */
/** @global location */
+import React, { Suspense } from "react";
import { jsx, Global } from "@emotion/core";
import {
@@ -8,14 +9,16 @@ import {
Switch
} from "react-router-dom";
-import { CSSTransition, TransitionGroup } from "react-transition-group";
+import { HashLoader } from "react-spinners";
-import LandingPage from "./pages/LandingPage";
-import FormPage from "./pages/FormPage";
-import CallbackPage from "./pages/CallbackPage";
+import { CSSTransition, TransitionGroup } from "react-transition-group";
import globalStyles from "./globalStyles";
+const LandingPage = React.lazy(() => import("./pages/LandingPage"));
+const FormPage = React.lazy(() => import("./pages/FormPage"));
+const CallbackPage = React.lazy(() => import("./pages/CallbackPage"));
+
const routes = [
{ path: "/", Component: LandingPage },
{ path: "/form/:id", Component: FormPage},
@@ -36,7 +39,11 @@ function App() {
>
<Switch location={location}>
{routes.map(({path, Component}) => (
- <Route key={path} exact path={path} component={Component}/>
+ <Route exact key={path} path={path}>
+ <Suspense fallback={<HashLoader color="white"/>}>
+ <Component/>
+ </Suspense>
+ </Route>
))}
</Switch>
</CSSTransition>