Commit ba246446 authored by Henrik Wenz's avatar Henrik Wenz Committed by Tim Neutkens

Remove useMemo from apollo examples (#8815)

We don’t need useMemo here since its functionality is already covered by initApolloClient.

Thanks to @mpoisot

closes #8810
parent d0b982b0
import React, { useMemo } from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import { ApolloProvider } from '@apollo/react-hooks' import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client' import { ApolloClient } from 'apollo-client'
...@@ -16,10 +16,7 @@ let apolloClient = null ...@@ -16,10 +16,7 @@ let apolloClient = null
*/ */
export function withApollo (PageComponent, { ssr = true } = {}) { export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => { const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo( const client = apolloClient || initApolloClient(apolloState)
() => apolloClient || initApolloClient(apolloState),
[]
)
return ( return (
<ApolloProvider client={client}> <ApolloProvider client={client}>
<PageComponent {...pageProps} /> <PageComponent {...pageProps} />
......
import React, { useMemo } from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import cookie from 'cookie' import cookie from 'cookie'
import Head from 'next/head' import Head from 'next/head'
...@@ -19,15 +19,7 @@ import fetch from 'isomorphic-unfetch' ...@@ -19,15 +19,7 @@ import fetch from 'isomorphic-unfetch'
*/ */
export function withApollo (PageComponent, { ssr = true } = {}) { export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => { const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo(() => { const client = apolloClient || initApolloClient(apolloState, { getToken })
// We pass in the apolloClient directly when using getDataFromTree
if (apolloClient) {
return apolloClient
}
// Otherwise initClient using apolloState
return initApolloClient(apolloState, { getToken })
}, [])
return ( return (
<ApolloProvider client={client}> <ApolloProvider client={client}>
<PageComponent {...pageProps} /> <PageComponent {...pageProps} />
......
import React, { useMemo } from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import { ApolloProvider } from '@apollo/react-hooks' import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client' import { ApolloClient } from 'apollo-client'
...@@ -18,10 +18,7 @@ let apolloClient = null ...@@ -18,10 +18,7 @@ let apolloClient = null
*/ */
export function withApollo (PageComponent, { ssr = true } = {}) { export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => { const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo( const client = apolloClient || initApolloClient(apolloState)
() => apolloClient || initApolloClient(apolloState),
[]
)
return ( return (
<ApolloProvider client={client}> <ApolloProvider client={client}>
<PageComponent {...pageProps} /> <PageComponent {...pageProps} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment