[英]React event handler
In this React event handling code, is there any semicolon missing?在这个 React 事件处理代码中,是否缺少任何分号? Because when I run it shows missing semicolon in line X:
因为当我运行它时,它在 X 行显示缺少分号:
changemessage () {
this.setState({ message: " Thanks for sub" })
}
I guess you want:我猜你想要:
function changemessage() {
this.setState({ message: " Thanks for sub" })
}
Or:或者:
changemessage = () => {
this.setState({ message: " Thanks for sub" })
}
Because the way you wrote it is incorrect (assuming this is not part of a class-based component), it might be expecting a semicolon here, thinking you were trying to invoke changemessage
, but that's not the case:因为您编写它的方式不正确(假设这不是基于类的组件的一部分),所以它可能会在这里期待一个分号,认为您正在尝试调用
changemessage
,但事实并非如此:
changemessage (); { this.setState({ message: " Thanks for sub" }) }
👆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.