微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React 中的中继样式分页

如何解决React 中的中继样式分页

中继式分页如何在反应中工作,就像它适用于一个查询而不适用于另一个查询。我需要更改其中的某些内容吗?在旧查询中,fetchmore 函数获取新产品并在页面显示旧产品。但是,fetchmore 会获取查询的数据,但不会在屏幕上更新它,而是在屏幕上显示旧数据。

const cache = new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
            products: relayStylePagination()
     }
   }
});

查询

const QUERY = gql`
  query Fetch($handle: String!,$after: String,$first: Int,$before: String) {
    collectionByHandle(handle: $handle) {
      id
      description
      products(first: $first,after: $after,before: $before) {
        edges {
          node {
            id
            description
            priceRange {
              minVariantPrice {
                amount
                currencyCode
              }
            }
            updatedAt
            productType
            title
            images(first: 1) {
              edges {
                node {
                  transformedSrc(maxWidth: 300)
                }
              }
            }
          }
          cursor
        }
        pageInfo {
          hasNextPage
        }
      }
    }
  }
`;

查询

const QUERY = gql`
  query productFetch($first: Int,$query: String) {
    products(first: $first,query: $query) {
      edges {
        node {
          priceRange {
            minVariantPrice {
              amount
              currencyCode
            }
          }
          updatedAt
          productType
          title
          images(first: 1) {
            edges {
              node {
                transformedSrc(maxWidth: 300)
              }
            }
          }
        }
        cursor
      }
      pageInfo {
        hasNextPage
      }
    }
  }
`;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。