1

Kindly correct me if I'm wrong.

() => this.handleClick()

is same as

function callHandleClick(){

return this.handleClick()

}

But the below works.

<input type="submit" onClick={ () => this.handleClick() }/>

But, this doesn't

<input type="submit" onClick={function callHandleClick(){return this.handleClick()}}/>

I have defined the handleClick method. Is it possible to use a normal function instead of arrow function to handle the click event?

1

1 Answer 1

1
() => this.handleClick()

is not the same as

function callHandleClick(){
  return this.handleClick()
}

The equivalent for that would be:

const callHandleClick = () => this.handleClick()

Therefore, you are defining a function inside the handleClick. Instead define it outside and pass it like:

onClick={callHandleClick}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.