简体   繁体   中英

React event handler

In this React event handling code, is there any semicolon missing? Because when I run it shows missing semicolon in line 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 (); { this.setState({ message: " Thanks for sub" }) }
                👆

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM