我正在构建一个应用程序来展示 Nextjs 13 中 Suspense 的用法。但是加载时 Suspense 回退并未显示。
这是page.js
import React, { Suspense } from "react";
import Loading from "./loading";
const Trending = React.lazy(() => import("./Trending"));
function Page() {
return (
<div>
<Suspense fallback={<Loading />}>
<Trending />
</Suspense>
</div>
);
}
export default Page;
Run Code Online (Sandbox Code Playgroud)
这里是流行趋势
import axios from "axios";
export default async function Trending() {
const res = await axios.get(
`https://api.themoviedb.org/3/trending/movie/day?api_key=1428e09fe38be9df57355a8d6198d916`
);
const data = res.data;
// Add a delay to ensure that the Suspense fallback is shown
await new …
Run Code Online (Sandbox Code Playgroud)