Skip to content

Instantly share code, notes, and snippets.

@yuritoledo
Last active November 27, 2019 13:57
Show Gist options
  • Select an option

  • Save yuritoledo/fcca512185861d445f8e6e277bc39040 to your computer and use it in GitHub Desktop.

Select an option

Save yuritoledo/fcca512185861d445f8e6e277bc39040 to your computer and use it in GitHub Desktop.
import React from "react";
import { useFormik } from "formik";
const initialValues = {
name: "",
email: "",
address: {
street: "",
city: ""
},
password: "",
confirmPassword: ""
};
const MyForm = () => {
const onSubmit = values => {};
const formik = useFormik({
initialValues,
onSubmit
});
return (
<div>
<form>
<input placeholder="Name" {...formik.getFieldProps("name")} />
<br />
<input placeholder="Email" {...formik.getFieldProps("email")} />
<br />
<input placeholder="Password" {...formik.getFieldProps("password")} />
<br />
<input
placeholder="confirm password"
{...formik.getFieldProps("confirmPassword")}
/>
<br />
<input
placeholder="Address"
{...formik.getFieldProps("address.street")}
/>
<br />
<input placeholder="City" {...formik.getFieldProps("address.city")} />
</form>
<div style={{ textAlign: "left" }}>
<pre>{JSON.stringify(formik.values, null, 2)}</pre>
</div>
</div>
);
};
export default MyForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment