1
試圖學習React。在我的示例應用程序中,其他組件需要知道文檔(textarea的內容)是否未保存。this.prop踐踏textarea更改處理程序
我正在嘗試的一種方法是讓我的父組件注入一個可以由子「編輯器」組件調用的支柱。
除了當從文本區調用handleChange
時,this.props
不再引用編輯器。我確信我有this
踐踏,但我們不確定推薦的解決方法。
export default class Editor extends React.Component {
constructor(props) {
super(props);
console.log(this.props);
}
handleChange(event) {
console.log(this.props);
// this.props.setUnsaved(true);
}
render() {
return <textarea onChange={this.handleChange} />;
}
};
如果有更好的方式來分享「未保存」的狀態,我向他們開放。最終我需要一個更好的模型系統,並可能使用Backbone。
我想我錯過了這樣的事情,謝謝。 – helion3