【发布时间】:2019-05-27 13:57:33
【问题描述】:
我试图理解为什么我们必须将对象 null 绑定到函数
add(text) {
this.setState(prevState=> ({
notes: [
...prevState.notes,
{
id: this.nextId(),
note: text
}
]
}))
}
render() {
return (
<div className="board">
{this.state.notes.map(this.eachNote)}
<button onClick={this.add.bind(null, "New Note")}
id="add">Add note</button>
</div>
)
}
为什么我们不能只做this.add("New Note")?
【问题讨论】:
-
添加null后是否按预期工作?
-
这个[链接]可能重复,你可以从这个链接得到解释(stackoverflow.com/questions/38334062/…)
-
传递
null不应该工作。你确定有吗?
标签: javascript reactjs ecmascript-6