我的处女作《Canvas系列教程》在我的Github上正在连载更新,希望能得到您的关注和支持,让我有更多的动力进行创作。
教程介绍、教程目录等能在README里查阅。
react中使用redux-thunk后获取input数据时
<Input className='divInput' onChange={e=>this.props.handleChangeInput(e)}/>
const mapStateToProps = (state) => {
return {
}
}
const mapDispatchToProps = (dispatch) => {
return {
handleChangeInput(e) {
console.log(e);
}
}
}
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(NewtonRing));
如果此时打开控制台,触发onChange事件时,输出如下
发现点击target后面的省略内容时显示为null,随后下面出现了warning
Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `target` on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://fb.me/react-event-pooling for more information.
function.console.(anonymous function) @ index.js:1446
warningWithoutStack @ react-dom.development.js:520
warn @ react-dom.development.js:1707
get @ react-dom.development.js:1701
invokeGetter @ VM213068:2
“这是出于性能原因。因此,您无法以异步方式访问该事件。”google后发现,其实可以暂时无视这个warning,然后偶然间发现
在这个位置已经显示出来了,于是在将代码稍作改动
将console.log(e); 改成 console.log(e.target);
然后再次触发事件
成功输出!完美!
不过为什么这个两个位置会有不一样的结果,可能是跟console调试有关,欢迎大家留言解释这个区别。