From 81c63a4ed2e849b138c3c41f067c6bd7a13de2c4 Mon Sep 17 00:00:00 2001 From: qsliu Date: Sun, 14 Jan 2024 17:28:09 +0800 Subject: [PATCH] use lazy & Suspense --- bun.lockb | Bin 52795 -> 52795 bytes src/main.jsx | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bun.lockb b/bun.lockb index be5936ff13e98cd0ddc7caf379da10f9a45195cc..60671f18aab0b13c2ccebe433a053043760687dc 100755 GIT binary patch delta 154 zcmV;L0A>HXoCCX@1CTBtKMdU|iEk-H5PHq2UU58P#;U++n;LCJzYX3z?vhsuu}-EG z0RodTBrB632?(<&6)i469WZjZrgOu)tv(>m=WWxsYD=_CitOl{P(N(ALQt&r0$~cP z9=`Y(W%^bpOs9p55Da{vGU delta 146 zcmV;D0B!%foCCX@1CTBt(MsqpAX2>c29qma( A3;+NC diff --git a/src/main.jsx b/src/main.jsx index 1739915..9462b0c 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -1,25 +1,32 @@ import { render } from "preact"; +import { lazy, Suspense } from "preact/compat"; import { useState } from "preact/hooks"; -import CsvSplit from "./csv"; -import StringToUtf8CodePoint from "./utf"; -const layouts = new Map([ - ["utf", (key) => ], - ["csv", (key) => ], -]); +const CsvSplit = lazy(() => import("./csv")); +const StringToUtf8CodePoint = lazy(() => import("./utf")); + +const layouts = ["utf", "csv"]; render(, document.getElementById("app")); function App() { - const [layout, setLayout] = useState(layouts.keys().next()?.value); + const [layout, setLayout] = useState(layouts[0]); return ( <> - {layouts.get(layout)(layout)} + Loading...}> + {layout === "utf" ? ( + + ) : layout === "csv" ? ( + + ) : ( +
Unknown
+ )} +
); }