xnimorz/use-debounce

react synthetic event error

Closed this issue · 2 comments

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.
I add persist event, but nothing happened
image
image

Hello, @uncle-link . Thank you for the issue.
When you set up the debounced callback as a react event listener, this callback will be called asynchronously, by timeout.
It means you should call event.persist() or cache necessary fields before debounced callback call.
In your example it could be:

const [ debouncePopoverOpen ] = useDebouncedCallback(target => {
  setAnchorEl(target);
});
// ...
<Typography 
  onMouseEnter={(e) => {
    const target = e.currentTarget; // or e.persist();
    debouncePopoverOpen(target);
  }}

You can check the example in this section: https://github.com/xnimorz/use-debounce#debounced-callbacks

Oh it works, and thk u so mc