0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsのストリーミングについて

Last updated at Posted at 2025-01-07

Qiita初投稿です。朝活でNext.jsの研鑽をしていました。

ストリーミングとは?

Next.jsのApp Routerで提供されるストリーミングは、サーバーからHTMLを段階的に送信して、ページを徐々に表示する技術

使い方

Reactのコンポーネントを活用

以下の例では、BlogListコンポーネントを取得している間に、fallbackで指定されているBlogListSkeltonを表示する。

import { Suspense } from 'react'
import BlogList from '@/components/BlogList'
import BlogListSkeleton from '@/components/BlogListSkeleton'
 
export default function BlogPage() {
  return (
    <div>
      {/* This content will be sent to the client immediately */}
      <header>
        <h1>Welcome to the Blog</h1>
        <p>Read the latest posts below.</p>
      </header>
      <main>
        {/* Any content wrapped in a <Suspense> boundary will be streamed */}
        <Suspense fallback={<BlogListSkeleton />}>
          <BlogList />
        </Suspense>
      </main>
    </div>
  )
}

所感

記事投稿で「ストリーミング」タグとしたが、一般的なストリーミングは動画のストリーミングサーバーのことかも?
ただ、ストリーミングサーバーについても、動画を全てダウンロードしなくても動画を再生できる仕組みなので、実現したいことは似ているのかなと思った。

参考

Next.jsドキュメント、ストリーミングについて

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?