unstable_noStore

unstable_noStore は、静的なレンダリング (static rendering) を明示的にオプトアウトし、特定のコンポーネントをキャッシュしないように指示するために使用できます。

import { unstable_noStore as noStore } from 'next/cache';

export default async function Component() {
  noStore();
  const result = await db.query(...);
  ...
}

補足情報:

  • unstable_noStore は、fetchcache: 'no-store' を指定するのと同等です
  • unstable_noStoreexport const dynamic = 'force-dynamic' よりも推奨されます。より細かい制御が可能で、コンポーネント単位で使用できるためです
  • unstable_cache 内で unstable_noStore を使用しても、静的な生成 (static generation) はオプトアウトされません。代わりに、結果をキャッシュするかどうかはキャッシュ設定に委ねられます。

使用方法

cache: 'no-store'next: { revalidate: 0 } のような追加オプションを fetch に渡したくない場合、これらのすべてのユースケースに対して noStore() を代替として使用できます。

import { unstable_noStore as noStore } from 'next/cache';

export default async function Component() {
  noStore();
  const result = await db.query(...);
  ...
}

バージョン履歴

バージョン変更内容
v14.0.0unstable_noStore が導入されました。