I love react-responsive for its MediaQuery
component which I can use as such:
<MediaQuery maxDeviceWidth={480}>
<button> Only show this on mobile </button>
</MediaQuery>
But what about in a function, like an event handler, when I want to do something based on if I'm on mobile or not?
For example, in the layout I have for mobile, I want a scroll to happen when selecting one of the elements. This scroll doesn't make sense in the desktop layout. So one of my click handlers should be something like:
onClick = () => {
if (responsive.isMobile()) {
window.scrollTo(0);
}
}
How can I achieve this?