在React中,是否可能将外部事件传递给setState的回调函数?
例子:
someFunc(event) {
this.setState(
{
value: event.target.value
},
() => {
this.props.onChange(event); // <- cannot pass to here
}
);
}
编辑:请查看Liam的优秀答案,下面是我问题的具体解决方案:
解决方案
someFunc(event) {
event.persist() // <- add this line and event should pass without a problem
this.setState(
{
value: event.target.value
},
() => {
this.props.onChange(event);
}
);
}