-1

I am trying to call two functions on the same onSubmit event in React. My approach is two wrap the two functions in a parent function, and call the parent function, as follows:

  Submit() { 
function1 () {}; 
function 2 () {}; 
}

Is there any glaring error in the way that I am going about this? I am getting a syntax error so I imagine it is a small error I am overlooking. Does the syntax above make sense?

user8891334
  • 171
  • 1
  • 4
  • 10

2 Answers2

2

you code dont look right... If you talking about calling 2 functions here is how:

   submit(){
//calling functions
this.function1();
this.function2();
}
//declaring functions
function1(){}
function2(){}
Mosd
  • 1,640
  • 19
  • 22
  • To add to this, if this is hooked on an onSubmit, one should pass the event as a parameter into submit() and call preventDefault() on the event – Kerry Gougeon Mar 30 '18 at 16:49
0

There are various to achieve the above task and one among them is the one you mentioned.

  • Method :
    You have syntax error in line 3 as there is space b/w function and 2.
    submit(){ func1(); func2(); }
    Also you'll find this link useful : Setting onSubmit in React.js