0
獲取無法從孩子
TypeError: Object doesn't support property or method 'setState'
嘗試從孩子父母設定的狀態改變父母的狀態。
父功能:
setSubject(id){
console.log(id);
this.setState({
currentSubject: id
});
<Subjects authToken = {this.state.authToken} subjects = {this.state.subjects} setSubject = {this.setSubject} />
子功能:
const listSubjects = this.props.subjects.map(subject => {
return(<div key={subject.id}>
<li data-toggle="collapse" data-target={"#" + subject.id}>{subject.title}</li>
<div id={subject.id} className="collapse">
<ul className="subject-features-list">
<li onClick={() => this.props.setSubject(subject.id)}>Egzamino programa</li>
<li>Egzaminai pagal metus</li>
</ul>
</div>
</div>
我在做什麼錯?
https://blog.andrewray.me/react-es6-autobinding-and-createclass/ :) –
Check this https://stackoverflow.com/questions/39503559/binding-error-on-react-causing- this-state-is-undefined-with-es6/39503728#39503728,setSubject函數綁定錯誤 –