Passing a click event to a function within a Promise tells me to use event.persist(), How?

末鹿安然 提交于 2019-12-24 07:17:20

问题


I have these 2 functions. I tried to pass the event "e" through to the promise, but in the "handleOnClick" function, e is null because it's out of the "this" scope. so I assigned the event to "this.clickEvent" and passed that instead, but now I get this long message about synethetic events and event.persist().

How do I fix this?

handleClick( e ) {
  this.clickEvent = e;
  somePromise( param1, param2 ).then( result => {
    handleOnClick( this.clickEvent, param1, param2 );
  });
}

handleOnClick( e, param1, param2 ) {
  if ( e.shiftKey ) { // get the below message in console here }
}

Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property shiftKey on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See fb.me/react-event-pooling for more information.


回答1:


As the error tells you, just call event.persist() (on whatever your event is).

More examples



来源:https://stackoverflow.com/questions/50710770/passing-a-click-event-to-a-function-within-a-promise-tells-me-to-use-event-persi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!