DEV Community

Discussion on: 10 useless NPM Package with millions of downloads

Collapse
jcubic profile image
Jakub T. Jankiewicz • Edited on

isMobile is not that useless. It's not that trivial to create this function yourself. But the code is just bunch of regex that tests userAgent string. It don't look very reliable. In one of my projects I have very long regex that test if something is mobile or even longer if it's a tablet.

Collapse
eliezerpp profile image
Eliezer Peña

In my personal experience is better check the viewport size (i.e: with window.matchMedia)

Collapse
jcubic profile image
Jakub T. Jankiewicz

I think that it fail on iPhone with retina in horizonntal mode. vewport size is not best way to test for mobile.

Thread Thread
eliezerpp profile image
Eliezer Peña

I think not, because the viewport pixels is not based on the real pixels of the device. You can also test and share your results ;)

Here is some documentation about how the CSS Units works webplatform.github.io/docs/tutoria...