I'm using Formik to submit my forms. I'm trying to add a custom params to my onSubmit function, so that I can get values of the form and that custom parameter.
const handleSubmit = async (customParam) => { console.log(customParam); console.log('Values : '); console.log(values); } <AppForm initialValues={{ rejectionComment: "" }} onSubmit={handleSubmit(myCustomParam)}> //My FORMIK form <AppFormField multiline={true} numberOfLines={4} name="rejectionComment" secured={false} autoCapitalize="none" autoCorrect={false}/> <SubmitButton title="Valider" /> //Validation button </AppForm> With this code, i'm able log the myCustomParam but I cannot get the values of the form [Unhandled promise rejection: ReferenceError: values is not defined]
If I change onSubmit to onSubmit={handleSubmit} and handleSubmit to const handleSubmit = async (values) => {console.log(values);} i can log my values, but cannot add my custom param.
Can you please provide some help ?
valuesdefined? Also, you're executing your handleSubmit function when you pass it to your AppForm. Wrap it as a callback, i.e.() => handleSubmit(myCustomParam)valuesis directly defined by onSubmit :onSubmit: (values: Values, formikBag: FormikBag) => void | Promise<any>