Why do I need to pass an anonymous function into the onClick event?

后端 未结 3 1010
刺人心
刺人心 2020-12-19 09:21

I\'ve been trying to learn the basics of React. However, I\'ve come across a section in the tutorial that asks me to place an alert() inside of an onClick event

3条回答
  •  醉酒成梦
    2020-12-19 09:58

    Because you need a function that gets called only in the instant that the button is clicked. If you pass alert('click') then the parser will find a function call and execute it instantly when it is going over that file.

提交回复
热议问题