Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!