From ba246446ef8069e160c3a9a010549e89e222dd1e Mon Sep 17 00:00:00 2001 From: Henrik Wenz Date: Sat, 21 Sep 2019 13:17:21 +0200 Subject: [PATCH] Remove useMemo from apollo examples (#8815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t need useMemo here since its functionality is already covered by initApolloClient. Thanks to @mpoisot closes #8810 --- .../apollo/client.js | 7 ++----- examples/with-apollo-auth/lib/apollo.js | 12 ++---------- examples/with-apollo/lib/apollo.js | 7 ++----- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/api-routes-apollo-server-and-client/apollo/client.js b/examples/api-routes-apollo-server-and-client/apollo/client.js index 4bba2b5af438..effd1af547a0 100644 --- a/examples/api-routes-apollo-server-and-client/apollo/client.js +++ b/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' @@ -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 ( diff --git a/examples/with-apollo-auth/lib/apollo.js b/examples/with-apollo-auth/lib/apollo.js index 592b971eea58..71f81a8ee8d4 100644 --- a/examples/with-apollo-auth/lib/apollo.js +++ b/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' @@ -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 ( diff --git a/examples/with-apollo/lib/apollo.js b/examples/with-apollo/lib/apollo.js index 303826b44c09..92007ffc300e 100644 --- a/examples/with-apollo/lib/apollo.js +++ b/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' @@ -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 (