在下一个js 13.4.5中无法加载组件
layout.jsx
"use client";
import React, { Suspense } from "react";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import CssBaseline from "@mui/material/CssBaseline";
import Loading from "./loading";
const darkTheme = createTheme({
palette: {
mode: "dark",
},
});
export default function RootLayout({ children }) {
return (
<ThemeProvider theme={darkTheme}>
<CssBaseline />
<html lang="en">
<title>auth</title>
<body>
<header></header>
<Suspense fallback={<Loading />}>
<main>{children}</main>
</Suspense>
<footer></footer>
</body>
</html>
</ThemeProvider>
);
}
loading.jsx
"use client";
import React from "react";
import CircularProgress from "@mui/material/CircularProgress";
function Loading() {
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "100vh",
}}
>
<CircularProgress />
</div>
);
}
export default Loading;
我试着问chatGPT,但它没有给予我一个明确的答案
我想让页面加载,而不是CSS样式尚未连接的页面
1条答案
按热度按时间tuwxkamq1#
要显示Suspense后备中的加载,我建议使用
React.lazy(() => import())
组件。Suspense不会检测何时在Effect或事件处理程序内提取数据。
友情链接:React DOCS