import React, { Component } from 'react'; import { Mutation, ApolloConsumer } from 'react-apollo'; import { SIGNIN_MUTATION, CURRENT_USER_QUERY } from '../queries/queries.graphql'; import Error from './ErrorMessage'; import Form from './styles/Form'; class Signin extends Component { state = { email: `wesbos@gmail.com`, password: 'abc123', }; loginUser = async (e, signin, client) => { e.preventDefault(); const res = await signin(); localStorage.setItem('token', res.data.signin.token); client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); }; saveToState = e => { const { name, value } = e.target; this.setState({ [name]: value }); }; render() { return ( {client => ( {(signin, { loading, error }) => (
this.loginUser(e, signin, client)}>
)}
)}
); } } export default Signin;