【问题标题】:Is there a way to pass an Apollo query selection through react props?有没有办法通过反应道具传递阿波罗查询选择?
【发布时间】:2017-07-07 10:34:27
【问题描述】:

响应 Apollo 调用以填充数据道具的方式

   graphql(withQLTag)(ReactComponent) 

存在于组件类之外。

但是如果我想通过预定义的查询来控制我通过 react 属性使用哪些数据,以便我可以为多个数据模型重用列表?(我知道列表视图必须从所有数据中存在的属性中提取返回)

   render() {
       return(
          <ReactComponent qlTag="Model1">
       )...

有没有办法解决这个问题?

【问题讨论】:

    标签: reactjs graphql apollo


    【解决方案1】:

    您可以制作任意数量的包装组件:

    import MyListComponent from './somewhere';
    
    const ProductListComponent = graphql(ProductListQuery)(MyListComponent) 
    const EventListComponent = graphql(EventListQuery)(MyListComponent) 
    const SomethingElseListComponent = graphql(SomethingElseListQuery)(MyListComponent) 
    

    graphql 包装器想象成只是创建了一个传递一些道具的组件。

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2019-09-28
      • 2018-04-04
      • 2017-07-21
      • 1970-01-01
      • 2019-07-06
      相关资源
      最近更新 更多