react-component / util

Common Utils For React Component
util.vercel.app
MIT License
623 stars 178 forks source link

fix: addEventListenerWrap param target may be nullish #445

Closed zerosrat closed 1 year ago

zerosrat commented 1 year ago

When target is nullish, it will throw TypeError: Cannot read properties of null (reading 'addEventListener'). So I add the optional chaining to avoid the error.

@zombieJ

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
util ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2023 8:36am
zombieJ commented 1 year ago

It's strange to provide empty as target. But this code seems fine.

zerosrat commented 1 year ago

It's strange to provide empty as target. But this code seems fine.

The origin issuse is from stickyScrollBar of rc-table. The code is as follows:

React.useEffect(function () {
    var onMouseUpListener = addEventListener(document.body, 'mouseup', onMouseUp, false);
}, [])

When invoking addEventListener in useEffect, document.body is null. Add null check can avoid the error log, but it still cannot add listener as expected.

@zombieJ