aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-04-13 22:43:46 -0400
committerGalen Guyer <galen@galenguyer.com>2022-04-13 22:43:46 -0400
commit28f7dec7e98a9065568b88a226bedcecad3a8250 (patch)
tree94815eb92521e5750f8b2640f03245d3b17e9261
parentc03a83e06f13e0d0fdd292c27221070964fa33fb (diff)
add lazy loading
-rw-r--r--src/App.jsx79
1 files changed, 48 insertions, 31 deletions
diff --git a/src/App.jsx b/src/App.jsx
index 42c3f36..5afcb03 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,10 +1,10 @@
import { useLocation, Routes, Route, Link } from "react-router-dom";
-import { useState } from "react";
+import { useState, lazy, Suspense } from "react";
import useFetch from "./useFetch";
-import Index from "./pages/Index";
import { DateTime } from "luxon";
import "./App.css";
-import Graph from "./pages/Graph";
+const Index = lazy(() => import("./pages/Index"));
+const Graph = lazy(() => import("./pages/Graph"));
import { useEffect } from "react";
const App = () => {
@@ -12,9 +12,10 @@ const App = () => {
let routerLocation = useLocation();
useEffect(() => {
- !window.goatcounter ?? window.goatcounter.count({
- path: location.pathname + location.search + location.hash,
- });
+ !window.goatcounter ??
+ window.goatcounter.count({
+ path: location.pathname + location.search + location.hash,
+ });
}, [routerLocation]);
const response = useFetch(url);
@@ -47,48 +48,64 @@ const App = () => {
<Route
path="/totalstudents"
element={
- <Graph
- name={"Total Student Cases"}
- response={response}
- dataKey={"total_students"}
- timeDifference={timeDifference}
- />
+ <Suspense fallback={null}>
+ <Graph
+ name={"Total Student Cases"}
+ response={response}
+ dataKey={"total_students"}
+ timeDifference={timeDifference}
+ />
+ </Suspense>
}
></Route>
<Route
path="/totalstaff"
element={
- <Graph
- name={"Total Staff Cases"}
- response={response}
- dataKey={"total_staff"}
- timeDifference={timeDifference}
- />
+ <Suspense fallback={null}>
+ <Graph
+ name={"Total Staff Cases"}
+ response={response}
+ dataKey={"total_staff"}
+ timeDifference={timeDifference}
+ />
+ </Suspense>
}
></Route>
<Route
path="/newstudents"
element={
- <Graph
- name={"New Student Cases"}
- response={response}
- dataKey={"new_students"}
- timeDifference={timeDifference}
- />
+ <Suspense fallback={null}>
+ <Graph
+ name={"New Student Cases"}
+ response={response}
+ dataKey={"new_students"}
+ timeDifference={timeDifference}
+ />
+ </Suspense>
}
></Route>
<Route
path="/newstaff"
element={
- <Graph
- name={"New Staff Cases"}
- response={response}
- dataKey={"new_staff"}
- timeDifference={timeDifference}
- />
+ <Suspense fallback={null}>
+ <Graph
+ name={"New Staff Cases"}
+ response={response}
+ dataKey={"new_staff"}
+ timeDifference={timeDifference}
+ />
+ </Suspense>
}
></Route>
- <Route exact path="/" element={<Index response={response} timeDifference={timeDifference} />} />
+ <Route
+ exact
+ path="/"
+ element={
+ <Suspense fallback={null}>
+ <Index response={response} timeDifference={timeDifference} />
+ </Suspense>
+ }
+ />
</Routes>
<footer>
<p>