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

174
Vistas
Pass a function with predefined parameter to handleSubmit in React

I have a redux-form inside a component "MyEditDataForm" and I am passing a function for handling submit to it like this:

const myHandleSubmit = ({ firstInputFieldName, secondInputFieldName }) => {
  console.log(firstInputFieldName);
  console.log(secondInputFieldName);
};

const EditDataPage = () => {
  return (
    <Container>
      <Row>
        <MyEditDataForm
          onSubmit={myHandleSubmit}
        />
      </Row>
    </Container>
  );
};

Console output: "john", "doe"

So far so good... Now I would like to add a parameter to myHandleSubmit, which I want to pass to myHandleSubmit. Like this:

const myHandleSubmit = ({ firstInputFieldName, secondInputFieldName, anotherParameter }) => {
  console.log(firstInputFieldName);
  console.log(secondInputFieldName);
  console.log(anotherParameter);
};

const EditDataPage = () => {
  const aNewParameter = "some info";

  return (
    <Container>
      <Row>
        <MyEditDataForm
          onSubmit={myHandleSubmit({ anotherParameter: aNewParameter })}
        />
      </Row>
    </Container>
  );
};

Output before clicking the submit button: undefined, undefined, "some info"

After clicking the button: "Error: You must either pass handleSubmit() an onSubmit function or pass onSubmit as a prop"

How is it possible to pass aNewParameter to myHandleSubmit, without destroying the form submit functionality? I have tried to do this with bind():

<MyEditDataForm
  onSubmit={myHandleSubmit.bind({ anotherParameter: aNewParameter })}
/>

Output: "john", "doe", undefined

What am I doing wrong?

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

0

Probably you need this:

const myHandleSubmit = ({ firstInputFieldName, secondInputFieldName, anotherParameter }) => {
  console.log(firstInputFieldName);
  console.log(secondInputFieldName);
  console.log(anotherParameter);
};

const EditDataPage = () => {
  const aNewParameter = "some info";

  return (
    <Container>
      <Row>
        <MyEditDataForm
          onSubmit={(fields) => myHandleSubmit({ ...fields, anotherParameter: aNewParameter })}
        />
      </Row>
    </Container>
  );
};
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