Reactjs 有没有办法通过react道具传递Apollo查询选择?

Reactjs 有没有办法通过react道具传递Apollo查询选择?,reactjs,graphql,apollo,Reactjs,Graphql,Apollo,阿波罗呼叫填充数据道具的反应方式 graphql(withQLTag)(ReactComponent) 存在于组件类之外 但是,如果我想通过预定义查询通过react prop控制使用哪些数据,以便可以为多个数据模型重用列表,该怎么办?(我知道列表视图必须从所有返回数据中存在的属性中提取) render(){ 返回( )... 有没有办法做到这一点?您可以制作任意数量的包装组件: import MyListComponent from './somewhere'; const Pro

阿波罗呼叫填充数据道具的反应方式

   graphql(withQLTag)(ReactComponent) 
存在于组件类之外

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

render(){
返回(
)...

有没有办法做到这一点?

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

import MyListComponent from './somewhere';

const ProductListComponent = graphql(ProductListQuery)(MyListComponent) 
const EventListComponent = graphql(EventListQuery)(MyListComponent) 
const SomethingElseListComponent = graphql(SomethingElseListQuery)(MyListComponent) 
可以将
graphql
包装器看作是创建一个传递一些道具的组件

import MyListComponent from './somewhere';

const ProductListComponent = graphql(ProductListQuery)(MyListComponent) 
const EventListComponent = graphql(EventListQuery)(MyListComponent) 
const SomethingElseListComponent = graphql(SomethingElseListQuery)(MyListComponent)