gpt4 book ai didi

javascript - 在 mapDispatchToProps 中传递事件对象和参数

转载 作者:行者123 更新时间:2023-11-30 20:38:45 26 4
gpt4 key购买 nike

我希望能够在发送参数的同时访问 mapDispatchToProps 中的事件对象。你如何看待这件事?

这是我目前所拥有的:

const mapDispatchToProps = dispatch => ({
onRowClick: (id, event) => {
console.log(id, event)
},
})

在我看来:

<TR key={`${index}`} onClick={() => onRowClick(id, event)}>

但是,这是不正确的。如何分派(dispatch)事件、传递参数并访问事件对象?

最佳答案

我来告诉你why you shouldn't do it: :

The SyntheticEvent is pooled. This means that the SyntheticEvent object will be reused and all properties will be nullified after the event callback has been invoked. This is for performance reasons. As such, you cannot access the event in an asynchronous way.

但是,如果您需要,您可以这样做:

const mapDispatchToProps = dispatch => ({
onRowClick: (id, event) => {
console.log(id, event)
},
})

<TR key={`${index}`} onClick={(event) => {
event.persist(); // remove the synthetic event from the pool
onRowClick(id, event);
}}>

关于javascript - 在 mapDispatchToProps 中传递事件对象和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49518232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com