https://stackoverflow.com/a/63666289/1084300
This is really simple with just one line of code:
const touch = matchMedia('(hover: none)').matches;
- What? matchMedia?
- This is just a JS API to do CSS @media queries. And it is supported in modern browsers: https://caniuse.com/#feat=matchmedia. Of course, you may use such queries directly in CSS: