TypeError: Cannot read property 'contains' of null
See original GitHub issueWhat error is this? How to solve?
OutsideClickHandler.js:1 Uncaught TypeError: Cannot read property 'contains' of null
at OutsideClickHandler.onOutsideClick (webpack:///./~/react-dates/lib/components/OutsideClickHandler.js?:1:3926)
at eval (webpack:///./~/consolidated-events/lib/TargetEventHandlers.js?:1:1684)
at Array.forEach (native)
at TargetEventHandlers.handleEvent (webpack:///./~/consolidated-events/lib/TargetEventHandlers.js?:1:1620)
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Cannot read property 'contains' of null - Stack Overflow
I think your ref might be undefined after change to new page. So contains method is null . I don't have enough information...
Read more >[Solved] TypeError: Cannot read property 'contains' of null
The error I'm seeing is TypeError: Cannot read property 'contains' of null . It's like SSR is trying to manipulate a DOM that...
Read more >Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >Uncaught TypeError: Cannot read property 'contains ... - GitHub
Thank you for reporting this issue. Looks like lightGallery is not initialized properly. Could you please share the HTML and JavaScript code ...
Read more >TypeError: Cannot read property 'contains' of undefined
The program complains about the following line of code. I put in the line of code above it to make sure that grabbed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry to bump this issue, but I seem to have also encountered this error message.
I think the issue is that I have my own
<OutsideClickHandler>
wrapping the react-dates component which also has its own OutsideClickHandler. When the component is removed from the VirtualDOM, I think it tries to trigger the OutsideClickHandler internally?Would it be beneficial to the library to have a conditional wrapping this portion?: https://github.com/airbnb/react-dates/blob/master/src/components/OutsideClickHandler.jsx#L38
Something like
if (this.childNode)
?Or maybe, allow
onOutsideClick
as a prop to<DateRangePicker>
?Also, another thing that helped was removing the
consolidated-events
API from use within my custo m<OutsideClickHandler>
. For some reason that was causing issues.I think I’ve found a fix.