I have the following code:
const {
values,
handleChange,
setFieldValue,
handleSubmit,
isSubmitting,
isValid
} = useFormikContext();
And i have the formik form inside a const comp
const Body = () => {
...
return(
<Formik
....
....>
{props=>{
<Form>
... then some fields here... etc
...
...
</Form>
}}
</Formik>
}
It gives me this error:
I've also checked this question: Formik 2.0.1 useFormikContext formik values undefined
however it didnt work even writing useFormikContext() inside Body
This hook will only work if there is a parent Formik React Context from which it can pull from.
Source
Make sure you are using useFormikContext
in a descendant of <Formik>
Something like this:
<Formik>
<Form>
<MyApp />
</Form>
</Formik>
// MyApp.jsx
const MyApp = () => {
const formik = useFormikContext();
// do what you want with formik
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With