我想創建一個組件,將打印輸出文本到屏幕上,這是我正在工作。反應 - _this2.SetState不是一個函數
class SearchBar extends Component {
constructor(props) {
super(props);
this.state = { term: '' };
}
render() {
return (
<div className="search-bar">
<input value={this.state.term} onChange={event => this.SetState(event.target.value)} />
The value of input is: {this.state.term}
</div>
);
}
}
但是我一直在Chrome控制檯得到一個錯誤:
bundle.js:19818 Uncaught TypeError: _this2.SetState is not a function
任何想法?
感謝
的可能的複製[無法訪問陣營實例(本)事件處理程序內(http://stackoverflow.com/questions/29577977/unable-to-access-react- instance-this-inside-event-handler) – vijayst