From 7af74ff8988961c988f03c95961b70c2918521ae Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 25 Aug 2017 09:33:53 -0400 Subject: yay --- components/Header.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 components/Header.js (limited to 'components/Header.js') diff --git a/components/Header.js b/components/Header.js new file mode 100644 index 0000000..52aeef9 --- /dev/null +++ b/components/Header.js @@ -0,0 +1,28 @@ +import { Component } from 'react' +import { graphql, compose } from 'react-apollo' +import { CURRENT_USER_QUERY } from '../queries'; + +class Header extends Component { + + componentDidMount() { + // This fetches the new data, but doesn't populate the user via props + // this.props.currentUserQuery.refetch(); + // This fetches the new data, and populates the user via props + setTimeout(this.props.currentUserQuery.refetch, 1); + } + + render() { + console.log(this.props.currentUserQuery.user); + const user = this.props.currentUserQuery.user || {}; + const { email = '' } = user; + + return ( +
+

{email} I'm the header!

+
+ ) + } +} + +const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUserQuery' }); +export default compose(userEnhancer)(Header) -- cgit v1.3