【问题标题】:Relay RefetchContainer does not update propsRelay RefetchContainer 不更新 props
【发布时间】:2019-02-17 06:26:09
【问题描述】:

我的 RefetchContainer 每次都使用相同的参数发出查询,但流向 refetchcontainer 组件的 props 没有更新。

这篇文章解释了为什么在使用 RefetchContainers https://github.com/facebook/relay/issues/2244时需要为片段使用变量

但是每次调用 refetch() 时都需要传递不同值的变量吗? 如何将新值放入我的道具中?

这是我的 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)
    }
  `
)

这里是 QueryRenderer graphql 查询:

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

【问题讨论】:

    标签: reactjs relay


    【解决方案1】:

    @Louis,您必须传递 refetchVariables 才能重新获取。例如,如果你有一个loadMore 函数,你可以有这样的东西:

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

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 2017-12-27
      • 2018-05-13
      • 2022-01-24
      • 1970-01-01
      • 2017-11-09
      • 2020-02-24
      • 2016-03-10
      • 2017-10-20
      相关资源
      最近更新 更多