unstable_noStore
在 15 版本中,我们推荐使用 connection
替代 unstable_noStore
。
unstable_noStore
可用于声明式地退出静态渲染,表明特定组件不应被缓存。
须知:
unstable_noStore
等效于在fetch
中使用cache: 'no-store'
- 相比
export const dynamic = 'force-dynamic'
,更推荐使用unstable_noStore
,因为它更细粒度且可以基于单个组件使用
- 在
unstable_cache
中使用unstable_noStore
不会退出静态生成。相反,它将遵从缓存配置来决定是否缓存结果。
用法
如果您不希望向 fetch
传递额外选项(如 cache: 'no-store'
、next: { revalidate: 0 }
),或者在 fetch
不可用的情况下,可以使用 noStore()
作为所有这些场景的替代方案。
版本历史
版本 | 变更 |
---|---|
v15.0.0 | unstable_noStore 被弃用,改用 connection 。 |
v14.0.0 | 引入 unstable_noStore 。 |