0

Just want to call to function on one click in react js

handleProjectSelection = (v1, v2) => () => {
    console.log(`${v1} and ${v2}`)
}
anotherfunctionCall = (ss) => () => {
    console.log(ss) 
}
<p onClick={() => { this.handleProjectSelection("sdsdsd", 'dksdsd'); this.anotherfunctionCall("second");}}> click event </p>

if there are two function with double arrow then i want to call both on one click in react

Towkir
  • 3,889
  • 2
  • 22
  • 41
  • Welcome to Stack Overflow - can you briefly describe the problem or error(s) you're getting with the code in your question? – Mark C. Jun 20 '19 at 13:11
  • Duplicate of [Call multiple functions onClick ReactJS](https://stackoverflow.com/questions/26069238/call-multiple-functions-onclick-reactjs) – Ionut Necula Jun 20 '19 at 13:15
  • The arrow function handler you have mentioned will also work. Basically, your click handler is referencing to a function which internally calls two functions. This is correct. – Aman Pandey Jun 20 '19 at 13:16
  • Hi,if i use single arrow for both of function then it's working but not for double arrow in react js. – Arvind Yadav Jun 20 '19 at 13:21

2 Answers2

1

You have to use only one arrow function to call in onClickevent.

handleProjectSelection = (v1, v2) => {
    console.log(`${v1} and ${v2}`)
}
anotherfunctionCall = (ss) => {
    console.log(ss) 
}
<p onClick={() => { this.handleProjectSelection("sdsdsd", 'dksdsd'); this.anotherfunctionCall("second");}}> click event </p>
Diamond
  • 3,470
  • 2
  • 19
  • 39
0
 handleOnClick = (v1,v2,ss) {
   handleProjectSelection(v1,v2);
   anotherfunctionCall(ss);
}

<p onClick={() =>{ this.handleOnClick("sdsdsd", 'dksdsd',"second")> click event </p>
ghazouan badr
  • 472
  • 5
  • 16