Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

676
Vistas
React Native & Formik pass custom params to onSubmit

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 ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do this with two changes.

  1. Change your handleSubmit function to accept two arguments (it also doesn't need to be async, unless you're doing more things than you have shown here).
const handleSubmit = (values, customParam) => {
  console.log({ values, customParam });
};
  1. Pass values where Formik provides them.
<AppForm
  onSubmit={values => { handleSubmit(values, myCustomParam); })}
  ...
>

Explanation:

When you change your code to onSubmit={handleSubmit), the Formik component calls it with the form values. The long form of this would be onSubmit={values => handleSubmit(values)}. Since your custom param is defined outside of Formik, you need to pass it in to the function manually.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Abe pointed the obvious. By using the callback, i've been able to define both values and custom params :

onSubmit={(values) => handleSubmit(values, "test")}

const handleSubmit = async (values, customParam) => {
    console.log(values);
    console.log(customParam);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda