react中使用redux-thunk后获取input数据,无法直接从console.log(e)中在控制台中展开target

本文探讨了在React应用中结合Redux-Thunk中间件处理input元素数据的方法。作者分享了如何正确访问合成事件的目标属性,避免警告并确保数据能被异步组件正确捕获。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我的处女作《Canvas系列教程》在我的Github上正在连载更新,希望能得到您的关注和支持,让我有更多的动力进行创作。

教程介绍、教程目录等能在README里查阅。

传送门:https://github.com/827652549/CanvasStudy

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调试有关,欢迎大家留言解释这个区别。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值