I'm using withFormik HOC and I need to access inner component props within handleSubmit handler.
Component is defined as
<MyForm mode='create' />
Some dummy handler is:
handleSubmit: (values, actions, { props } ) => {
console.log('SUBMIT:', props);
}
When I try to submit form, I got:
Cannot destructure propertypropsof 'undefined' or 'null'.
If I try with
handleSubmit: (values, actions, { ...props } ) => { i get undefined...
Hello,
Props are actually injected in the formikBag that is given as the second argument. The one you named actions. You can try this :
handleSubmit: (values, { props, ...actions } ) => {
console.log('SUBMIT:', props);
}
You can see a living example here : https://codesandbox.io/s/formik-example-oq6e0
Cheers,
Most helpful comment
Hello,
Props are actually injected in the formikBag that is given as the second argument. The one you named
actions. You can try this :You can see a living example here : https://codesandbox.io/s/formik-example-oq6e0
Cheers,