Passing a click event to a function within a Promi

2019-08-15 01:41发布

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.

标签: reactjs redux
1条回答
做自己的国王
2楼-- · 2019-08-15 02:15

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

More examples

查看更多
登录 后发表回答