Formik: How to access component props within handleSubmit and withFormik

Created on 23 Jul 2019  路  1Comment  路  Source: formium/formik

鉂換uestion

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...

stale

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 :

handleSubmit: (values, { props, ...actions } ) => {
  console.log('SUBMIT:', props);
}

You can see a living example here : https://codesandbox.io/s/formik-example-oq6e0

Cheers,

>All comments

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,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jordantrainor picture jordantrainor  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

ancashoria picture ancashoria  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments

sibelius picture sibelius  路  3Comments