小编Sur*_*rma的帖子

NextJS 13 中未显示 Suspense 回退

我正在构建一个应用程序来展示 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)

javascript reactjs next.js react-suspense next.js13

9
推荐指数
1
解决办法
8810
查看次数

标签 统计

javascript ×1

next.js ×1

next.js13 ×1

react-suspense ×1

reactjs ×1