我是 Nextjs 的新手,对 Nextjs 中的客户端渲染和服务器端渲染有一些疑问
useQuery钩子,但只能在 React 组件函数上调用。这是否意味着它仅在从客户端渲染页面时运行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)