I have been trying to come up with a way implement the submit function of the react-apollo
<Mutation>
component. Found some examples out there that seem to be an overkill for this simple task, including this and this. Since I am fresh programmer just starting to learn React, let alone Formik or even HOCs (I guess that's the way to go?), I can't really wrap my head around these examples and how to adapt them to my analogue Hello world
code.
Here's my sign up form:
import React, { Component } from "react";
import { withFormik, Form, Field } from "formik";
import { Mutation } from "react-apollo";
import { gql } from "apollo-boost";
const CREATE_USER_MUTATION = gql`
mutation CREATE_USER_MUTATION(
$name: String!
$email: String!
$password: String!
) {
signup(name: $name, email: $email, password: $password) {
id
name
email
password
permissions
}
}
`;
class App extends Component {
state = {
name: "",
email: "",
password: ""
};
render() {
return (
<Mutation mutation={CREATE_USER_MUTATION}>
{(signup,{loading}) => (
<Form>
<Field type="text" name="name" placeholder="Name" />
<Field type="email" name="email" placeholder="Email" />
<Field type="password" name="password" placeholder="Password" />
<button type="submit" disabled={loading}>
Sign Up
</button>
</Form>
)}
</Mutation>
);
}
}
const SignupPage = withFormik({
mapPropsToValues() {
return {
name: "",
email: "",
password: ""
};
},
handleSubmit() { ... }
})(App);
export default SignupPage;
How can I access signup
in handleSubmit
?