0

In my react component + recompose I am trying to load a graphql dynamically depending on some props but if I use withProps the data is always undefined. I don't understand how to connect the withProps function with the branch in order to wait for the data to load.

My component:

`export const SimplePage = ({match, route, data: { post } }) => (
   ...
)

const enhance = compose(
  withProps(props => graphql(resolveQuery(props.match.params))),
  showApolloError(),
  showSpinnerWhileApolloLoading()
)`

In this case data is always undefined. If I don't use withProps the query works fine (but I cannot pass props in order to load different queries).

Any ideas of how to approach this without duplicating the component? Thanks!

Elisa M.
  • 51
  • 5
  • what is the data type? – Omar Apr 12 '18 at 16:11
  • data is the response from the graphQL query. The response is correct but for some reason once I use withProps I cannot manage to wait for the response before rendering the component – Elisa M. Apr 17 '18 at 06:37
  • Why you need `withProps`? You get the props inside of the `graphql(Query, {options: (props) => ({varibales : props})})` as well – Andreas Köberle Apr 18 '18 at 13:01
  • Yes, but I would like to create the query dynamically depending on the variable passed to the component, also with different type (not only variables for the query – Elisa M. Apr 18 '18 at 14:58

0 Answers0