This is the code:
class Seismo extends Component {
constructor(props) {
super(props);
this.state = {
news: ""
}
this.updateNews = this.updateNews.bind(this)
}
updateNews = () => {
console.log('test')
}
What I am trying to do is to fire the updateNews
code from render
:
render() {
return (
<Button
type="primary"
onClick={async () => {
this.updateNews // This is what I am trying to fire!
}
>TEST</Button>
But keep getting this error:
Uncaught Error: this.updateNews is not a function
You were not calling the functuion
<Button
type="primary"
onClick={async () => {
this.updateNews() // This is what I am trying to fire!
}
>TEST</Button>
Note: You do need to bind because you use arrow function.
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.