React,Apollo,apollo-link-state。无用的重新渲染简单组件。 DEMO

时间:2018-03-04 04:37:20

标签: reactjs react-native apollo react-apollo apollo-client

这是控制台日志: image

复制演示在这里:https://codesandbox.io/s/8n89yrwjx0

这是相关代码:

const cache = new InMemoryCache();

const stateLink = withClientState({
  cache,
  resolvers: {
    Mutation: {
      updateStatus: (_, { isEnabled }, { cache }) => {
        const data = {
          status: {
            __typename: "status",
            isEnabled
          }
        };
        cache.writeData({ data });
        return null;
      }
    }
  },
  defaults: {
    status: {
      __typename: "status",
      isEnabled: false
    }
  }
});

const client = new ApolloClient({
  link: stateLink,
  cache
});

每次重新呈现Hello组件。的为什么吗

我在Chrome控制台中注意到" refetch"丙

但是,无论如何,如果我使用这段代码:

export default graphql(STATUS_QUERY, {
    props: ({ data: { loading, error, isEnabled } }) => {
      if (loading) {
        return { loading };
      }

      if (error) {
        return { error };
      }

      return {
        loading: false,
        isEnabled
      };
    }
  }
)(Hello);

似乎重新渲染,因为props因引用而异。的为什么吗

0 个答案:

没有答案
相关问题