Last active
June 23, 2018 11:01
-
-
Save zapkub/e62b5c0543434fb0c14596898d9d5a13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import { graphql } from 'react-apollo' | |
import gql from 'graphql-tag' | |
const USER_INFOMATION_QUERY = gql` | |
query { | |
user { | |
_id | |
} | |
} | |
` | |
// create Query HOC | |
const withUserQueryData = graphql(USER_INFOMATION_QUERY, { | |
props: ({ data }) => { | |
if(!data.user) { return {} } | |
return { | |
user: data.user | |
} | |
} | |
}) | |
type UserInfoComponentPropTypes = { | |
user: UserInfoData | |
} | |
const UserInfoComponent: React.SFC<UserInfoComponentPropTypes> = () => { ....return some component } | |
// enhance with data | |
export default withUserQueryData(UserInfoComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment