Skip to content

Instantly share code, notes, and snippets.

@ncrmro
Created June 2, 2017 10:18
Show Gist options
  • Save ncrmro/99778af3c5c0cb8c4391c6cbdd91515e to your computer and use it in GitHub Desktop.
Save ncrmro/99778af3c5c0cb8c4391c6cbdd91515e to your computer and use it in GitHub Desktop.
import React from 'react';
import { graphql, QueryRenderer } from 'react-relay';
function withRelayContainer(WrappedComponent, selectData) {
return ({environment, variables, router}) =>
<QueryRenderer
environment={environment}
query={graphql`
query PollsContainerQuery($id: ID!) {
question(id: $id) {
id
...PollsVote_question
...PollsResults_question
}
}
`}
variables={{ id: router.match.params.id }}
render={({ error, props }) => props ?
<WrappedComponent
{...props}
router={router}
environment={environment}
initialVariables={{ id: router.match.params.id }}
/> :
<div>loading...</div> }
/>
}
export default withRelayContainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment