【发布时间】:2021-03-27 10:31:31
【问题描述】:
这是修改后的代码。
<textarea
className= "textarea"
placeholder="write the description here"
value={this.state.input}
onChange={(ev) => {
this.updateBody(ev.target.value)
}
}>
</textarea>
然后我调用函数以将数据保存到 Firebase。
updateBody = async (val) => {
await this.setState({ input: val });
await this.setState({ wordsCounted :val.split(' ').length });
await this.setState({charactersCounted : val.length })
/*assign the number of words inside the textarea to the variable wordsCounted*/
this.update();
};
updateTitle = async (txt) => {
await this.setState({ title: txt });
this.update();
}
update = debounce(() => {
this.props.noteUpdate(this.state.id, {
title: this.state.title,
body: this.state.input,
/*Send the value of the var wordsCounted to Firebase*/
wordsCounted : this.state.wordsCounted,
charactersCounted : this.state.charactersCounted
})
}, 750);
问题是我不知道为什么title 和body 被保存,而wordsCounted 和charactersCounted 没有。
【问题讨论】: