【问题标题】:Relay: Composing child fragments中继:组合子片段
【发布时间】:2016-10-01 14:47:00
【问题描述】:

使用反应路由器:

<Routes>
  <Route path="/" component={App}>
    <Route path="about" component={About} />
    <Route path="help" component={Help} />
  </Route>
</Routes>

在应用中:

render() {
 return (
   {this.props.children}
  );
}

如果在 App 容器上我组成孩子的片段

${About.getFragment(somefragment)}
${Help.getFragment(someFragment)}

如果组件用 {this.props.children} 表示为子组件,而不是用 , 从它们的类实例化,是否会中继组合片段?

问题是使用语法为 {this.props.children} 的子级是否与中继的聚合片段逻辑一起使用?

【问题讨论】:

    标签: reactjs react-router relayjs


    【解决方案1】:

    这应该可行,但是将所有片段存储在最高父级组件中并不是最佳做法。使用 Relay,其想法是您希望在使用类实例化的组件旁边声明数据需求。这样一来,您就可以准确地知道从 GraphQL 服务器为每个组件获取哪些数据,保持每个组件的关注点分离,同时减少混乱。

    【讨论】:

      猜你喜欢
      • 2022-07-29
      • 1970-01-01
      • 2016-06-07
      • 2021-11-03
      • 1970-01-01
      • 2016-10-18
      • 2015-12-08
      • 1970-01-01
      • 2017-01-21
      相关资源
      最近更新 更多