- 此问题在此处已有答案**:
React - uncaught TypeError: Cannot read property 'setState' of undefined(20个答案)
20小时前关闭。
`I am getting the following error
React-未捕获类型错误:无法读取未定义的属性'setState'
import React, { Component } from "react";
class Message extends Component {
constructor() {
super();
this.state = {
message: "Welcome Visitor",
};
}
changeMessage(event) {
console.log("i am here");
this.setState({
message: "thank you for subscribing",
});
}
render() {
return (
<div>
<h1>{this.state.message}</h1>
<button onClick={this.changeMessage}>subscribing</button>
</div>
);
}
}
export default Message;
我已经创建了以下代码,但我不断地得到以下错误(很多)。它看起来像应用程序进入了一个循环:
1条答案
按热度按时间bd1hkmkf1#
必须导入useState