小编Tu *_*anh的帖子

useQuery 是否在服务器端渲染上运行?

我是 Nextjs 的新手,对 Nextjs 中的客户端渲染和服务器端渲染有一些疑问

  1. 我看到有两种方法可以在 Nextjs 上获取数据。其中之一是使用useQuery钩子,但只能在 React 组件函数上调用。这是否意味着它仅在从客户端渲染页面时运行
  2. 我读了一篇关于如何连接apolloClient到 Nextjs 的帖子。它说

总是apolloClient为 SSR创建一个新实例,并且只apolloClient为 CSR创建一个实例

这是示例代码

  export function initializeApollo(initialState = null) {
    const _apolloClient = apolloClient ?? createApolloClient();

    // If your page has Next.js data fetching methods that use Apollo Client,
    // the initial state gets hydrated here
    if (initialState) {
      // Get existing cache, loaded during client side data fetching
      const existingCache = _apolloClient.extract();

      // Restore the cache using the …
Run Code Online (Sandbox Code Playgroud)

apollo next.js apollo-client

3
推荐指数
1
解决办法
623
查看次数

标签 统计

apollo ×1

apollo-client ×1

next.js ×1