JSFiddle - React, Tailwind, and code Playground

HTML

Resize the framed window...

<div id="mydiv">
  the DIV
</div>

CSS

#mydiv {
  display: none;
}

@media (min-width:500px) {
  #mydiv {
    display: block
  }
}

JavaScript

var widthMatch = window.matchMedia("(min-width:500px)");
if(widthMatch.matches) {
  divIsVisible();
}
widthMatch.addListener(function(e){
  if(e.matches) {    
    divIsVisible();
  }
});

function divIsVisible(){
  console.log('DIV is visible!')
}