import React from 'react';
import { Formik, withFormik, useFormikContext } from 'formik';
const FormikBasic = () => (
{
$("#id").html(values.foo); // NOT OK
}}
onSubmit={(values, { setSubmitting }) => {
$("#id").html(values.bar); // NOT OK
}}
>
{(inputs) => (
)}
);
const FormikEnhanced = withFormik({
mapPropsToValues: () => ({ name: '' }),
validate: values => {
$("#id").html(values.email); // NOT OK
},
handleSubmit: (values, { setSubmitting }) => {
$("#id").html(values.email); // NOT OK
}
})(MyForm);
(function () {
const { values, submitForm } = useFormikContext();
$("#id").html(values.email); // NOT OK
$("#id").html(submitForm.email); // OK
})
import { Form } from 'react-final-form'
const App = () => (
)}
/>
);
function plainSubmit(e) {
$("#id").html(e.target.value); // NOT OK
}
const plainReact = () => (
)
import { useForm } from 'react-hook-form';
function HookForm() {
const { register, handleSubmit, errors } = useForm(); // initialize the hook
const onSubmit = (data) => {
$("#id").html(data.name); // NOT OK
};
return (
);
}
function HookForm2() {
const { register, getValues } = useForm();
return (
);
}
function vanillaJS() {
document.querySelector("form.myform").addEventListener("submit", e => {
$("#id").html(e.target.value); // NOT OK
});
document.querySelector("form.myform").onsubmit = function (e) {
$("#id").html(e.target.value); // NOT OK
}
}