summaryrefslogtreecommitdiffstats
path: root/components/Header.js
blob: 52aeef9133ea11fc77ee3f9b91f32e16c10db401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 (
      <div>
        <p>{email} I'm the header!</p>
      </div>
    )
  }
}

const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUserQuery' });
export default compose(userEnhancer)(Header)