Joseph Barnes
Joseph Barnes

Reputation: 640

Is there a way to pass an Apollo query selection through react props?

The way that react Apollo calls to populate the data prop

   graphql(withQLTag)(ReactComponent) 

exists outside the component class.

But what if I want to control which data I use via the react prop by predefined queries so that I can reuse a list for multiple data models?(I know the list view would have to pull from properties that exist in all data returned)

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

Is there a way to pull this off?

Upvotes: 1

Views: 426

Answers (1)

stubailo
stubailo

Reputation: 6147

You can make as many wrapped components as you like:

import MyListComponent from './somewhere';

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

Think of the graphql wrapper as just creating a component that passes in some props.

Upvotes: 1

Related Questions