From 13e2bf04cc471b5168539b460c69f2ba4bc5151b Mon Sep 17 00:00:00 2001 From: varun7654 Date: Mon, 6 May 2024 01:52:47 -0700 Subject: [PATCH] improve code splitting the problem page is still large b/c of the dependency on the editor, but at least the home pages should load quickly --- src/App.tsx | 10 ++++++---- src/problem/Problem.tsx | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 37f4c3a..a1ad6ba 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,8 @@ -import React from 'react'; +import React, {lazy} from 'react'; import {BrowserRouter as Router, Link, Route, Routes, useLocation} from 'react-router-dom'; import './App.css'; import 'highlight.js/styles/atom-one-dark.min.css'; -import {Problem} from "./problem/Problem"; -import Home from './Home'; import LoginButton from "./auth/LoginButton"; -import LoginSuccess from "./auth/LoginSuccess"; import {createTheme, Shadows} from "@mui/material"; export const API_URL = "https://codehelp.api.dacubeking.com/"; @@ -69,6 +66,11 @@ export function Header() { } } +const Home = lazy(() => import("./Home")); +const Problem = lazy(() => import("./problem/Problem")); +const LoginSuccess = lazy(() => import("./auth/LoginSuccess")); + + function App() { return ( diff --git a/src/problem/Problem.tsx b/src/problem/Problem.tsx index bbcc18e..b510c4f 100644 --- a/src/problem/Problem.tsx +++ b/src/problem/Problem.tsx @@ -44,7 +44,7 @@ function getStorageKey(id: string, userName: string | undefined) { return "problem " + id; } -export function Problem() { +export default function Problem() { const [problemData, setProblemData] = useState(null as unknown as ProblemData); const {"*": id} = useParams(); const [userData, setUserData] = useState(null as unknown as UserData);