Skip to content

Commit

Permalink
Remove useMemo from apollo examples (#8815)
Browse files Browse the repository at this point in the history
We don’t need useMemo here since its functionality is already covered by initApolloClient.

Thanks to @mpoisot

closes #8810
  • Loading branch information
HaNdTriX authored and timneutkens committed Sep 21, 2019
1 parent d0b982b commit ba24644
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
7 changes: 2 additions & 5 deletions examples/api-routes-apollo-server-and-client/apollo/client.js
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React from 'react'
import Head from 'next/head'
import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client'
Expand All @@ -16,10 +16,7 @@ let apolloClient = null
*/
export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo(
() => apolloClient || initApolloClient(apolloState),
[]
)
const client = apolloClient || initApolloClient(apolloState)
return (
<ApolloProvider client={client}>
<PageComponent {...pageProps} />
Expand Down
12 changes: 2 additions & 10 deletions examples/with-apollo-auth/lib/apollo.js
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import cookie from 'cookie'
import Head from 'next/head'
Expand All @@ -19,15 +19,7 @@ import fetch from 'isomorphic-unfetch'
*/
export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo(() => {
// We pass in the apolloClient directly when using getDataFromTree
if (apolloClient) {
return apolloClient
}

// Otherwise initClient using apolloState
return initApolloClient(apolloState, { getToken })
}, [])
const client = apolloClient || initApolloClient(apolloState, { getToken })
return (
<ApolloProvider client={client}>
<PageComponent {...pageProps} />
Expand Down
7 changes: 2 additions & 5 deletions examples/with-apollo/lib/apollo.js
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React from 'react'
import Head from 'next/head'
import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloClient } from 'apollo-client'
Expand All @@ -18,10 +18,7 @@ let apolloClient = null
*/
export function withApollo (PageComponent, { ssr = true } = {}) {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = useMemo(
() => apolloClient || initApolloClient(apolloState),
[]
)
const client = apolloClient || initApolloClient(apolloState)
return (
<ApolloProvider client={client}>
<PageComponent {...pageProps} />
Expand Down

0 comments on commit ba24644

Please sign in to comment.