Skip to content

Conversation

@zerosrat
Copy link
Contributor

@zerosrat zerosrat commented May 29, 2023

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
Copy link

vercel bot commented May 29, 2023

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
Copy link
Member

zombieJ commented May 29, 2023

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

@zombieJ zombieJ merged commit 615d435 into react-component:master May 29, 2023
@zerosrat
Copy link
Contributor Author

zerosrat commented May 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants