Cannot read property 'addListener' of null
See original GitHub issueJust trying a simple test of this library:
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import MediaQuery from 'react-responsive';
const toRender = (
<div>
<MediaQuery query='(min-device-width: 1224px)'>
<div>YES</div>
</MediaQuery>
</div>
);
ReactDOM.render(
toRender,
document.getElementById('app'),
);
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1, shrink-to-fit=no">
<title>Responsive Test</title>
</head>
<body style="background:#D3D3D3;">
<div id="app"></div>
<script type="text/javascript" src="/bundle.js"></script>
</body>
</html>
I’m getting this error :
Cannot read property 'addListener' of null
Looking into the code, it seems that the mq
state of index is null
by default.
Is there something I got wrong ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Cannot read property 'addEventListener' of null - Stack Overflow
On those pages where the function cannot find the id, I receive a "Cannot read property 'addEventListener' of null " error and none...
Read more >Uncaught TypeError cannot read property 'addeventlistener' of ...
In JavaScript, a very common error is the Uncaught TypeError Cannot read property 'addeventlistener' of null. This error occurs when JavaScript is not...
Read more >[SOLVED] Cannot Read Property 'addEventListener' of Null in ...
To fix the “cannot read property 'addEventListener' of null” error, make sure the selector used the access the element is properly defined.
Read more >Cannot read property 'addEventListener' of Null in JS
The error "Cannot read property addEventListener of null" occurs when we call the addEventListener() method on a DOM element that doesn't exist.
Read more >Cannot read property 'addEventListener' of null - JavaScript
I got this issue that I can't get passed. Tried to google it and searched on StackOverflow but still stuck.
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 Free
Top 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
Library requires 16.3+ - you’ll get a warning on install if you have any version lower than that. Update to 16.3 and it should fix the problem.
Nope 16.1.0