简体   繁体   English

中继RefetchContainer不更新道具

[英]Relay RefetchContainer does not update props

My RefetchContainer issues a query with the same arguments everytime but the props flowing to the refetchcontainer component are not updated. 我的RefetchContainer每次都发出带有相同参数的查询,但不会更新流到refetchcontainer组件的道具。

This post explains why it's necessary to use variables for your fragment when using a RefetchContainers https://github.com/facebook/relay/issues/2244 这篇文章解释了为什么在使用RefetchContainers https://github.com/facebook/relay/issues/2244时需要为片段使用变量

But is it necessary to pass variables with different values everytimes we call refetch()? 但是是否有必要在每次调用refetch()时传递具有不同值的变量吗? How can i get the new values into my props? 我怎样才能将新的价值融入我的道具?

Here is my createRefetchContainer: 这是我的createRefetchContainer:

export default createRefetchContainer(
  DashboardRefetchContainer,
  {
    dashboardData: graphql`
      fragment DashboardRefetchContainer_dashboardData on Query @argumentDefinitions(
        idFund: {type: "String!"},
      )
      {
        ...DashboardTopMetrics_lastIntraDay
        ...DashboardTopMetrics_last12Month
        specsFundByIdFund(idFund: $idFund) {
          lastOne: fundsByIdFund(orderBy: [CREATED_AT_DESC] first:1) {
            nodes {
              ...Risk_expo
              ...Risk_vars
              betaOneYear
              drawdown
              exposureNet
              cash
              turnover
              benchmark
              volatility1Y
              navY
              nbOrders
            }
          }
        }
        specsFundByIdFund(idFund: $idFund) {
          ...Risk_tresh
        }
      }
    `,
    dashboardGraphData: graphql`
    fragment DashboardRefetchContainer_dashboardGraphData on Query @argumentDefinitions(
      idFund: {type: "String!"},
      fundCond: {type: "FundCondition!"},
    ){
      // more items...
      allFunds(first:7 orderBy: [CREATED_AT_DESC] condition: $fundCond) {
        ...LineFragCount_item
        ...LineFragPerc_item
        ...LineFragWatch_item
      }
      todayAssetAllPortfolio: todayAssetAllPortfolio(idFund: $idFund) {
        nodes {
          name
          priceEur
          expoEur
          valueEur
          asset {
            id
            position
            currency
            perc
            underlyingByUnderlying {
              tickerBbg
              perfDay
              perfWtd
              perfYtd
            }
          }
        }
      }
    }
    `
  },
  graphql`
    query DashboardRefetchContainerRefetchQuery($idFund: String!, $fundCond: FundCondition!) {
      ...DashboardRefetchContainer_dashboardData @arguments(idFund: $idFund)
      ...DashboardRefetchContainer_dashboardGraphData @arguments(idFund: $idFund, fundCond: $fundCond)
    }
  `
)

And here the QueryRenderer graphql query: 这里是QueryRenderer graphql查询:

  query DashboardMainChartsQuery($idFund: String!, $fundCond: FundCondition!) {
    ...DashboardRefetchContainer_dashboardData @arguments(idFund: $idFund)
    ...DashboardRefetchContainer_dashboardGraphData @arguments(idFund: $idFund, fundCond: $fundCond)
  }

@Louis, you must pass a refetchVariables to refetch. @Louis,必须将refetchVariables传递给refetchVariables For example, if you have a loadMore function, you could have something like this: 例如,如果您具有loadMore函数,则可能会有以下内容:

  _loadMore() {
  // Increments the number of stories being rendered by 10.
  const refetchVariables = fragmentVariables => ({
    first: fragmentVariables.count + 10,
  });
  this.props.relay.refetch(refetchVariables);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM