import React from 'react'; import { Query, Mutation } from 'react-apollo'; import Form from './styles/Form'; import { CURRENT_USER_QUERY, UPDATE_USER_MUTATION } from '../queries/queries.graphql'; import Error from './ErrorMessage'; class EditUser extends React.Component { state = { changes: {}, }; handleChange = e => { const { name, value } = e.target; const changes = { ...this.state.changes, [name]: value, }; this.setState({ changes }); }; handleSubmit = async (e, updateUser) => { e.preventDefault(); // only submit if there are real changes if (Object.keys(this.state.changes).length === 0) return; await updateUser(); this.setState({ changes: {} }); }; render() { return ( {({ data: { me }, loading }) => { if (loading) return

Loading...

; return ( {(updateUser, { error, called }) => (
this.handleSubmit(e, updateUser)}>
{called && !error &&

Updated!

} me:
{JSON.stringify(me.name)}
Change:
{JSON.stringify(this.state.changes)}
)}
); }}
); } } export default EditUser;