网页 综合 更新时间 2026-03-03 00:00:00

Client-side Fetching

自动蜘蛛 nextjs.org 正文约 1512 字
Client-side Fetching
Client-side data fetching is useful when your page doesn't require SEO indexing, when you don't need to prerender your data, or when the content of your pages needs to update frequently. Unlike the server-side rendering APIs, you can use client-side data fetching at the component level.
If done at the page level, the data is fetched at runtime, and the content of the page is updated as the data changes. When used at the component level, the data is fetched at the time of the component mount, and the content of the component is updated as the data changes.
It's important to note that using client-side data fetching can affect the performance of your application and the load speed of your pages. This is because the data fetching is done at the time of the component or pages mount, and the data is not cached.
The following example shows how you can fetch data on the client side using the useEffect hook.
The team behind Next.js has created a React Hook library for data fetching called SWR. It is highly recommended if you are fetching data on the client-side. It handles caching, revalidation, focus tracking, refetching on intervals, and more.
Using the same example as above, we can now use SWR to fetch the profile data. SWR will automatically cache the data for us and will revalidate the data if it becomes stale.
For more information on using SWR, check out the SWR docs.
Last updated March 3, 2026
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies.
访问原文 返回搜索 https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。