react-device-detect
react-device-detect copied to clipboard
OsTypes.Android either not working, or documentation doesn't make sense
import { OsTypes } from 'react-device-detect';
...
if (OsTypes.Android) {
console.warn('* Android detected');
}
warns that it's Android no matter what browser/platform i'm on.
enums documentation seems to indicate that that should work?
Detect this way.
import { mobileVendor, mobileModel } from 'react-device-detect';
function App() {
console.log( "Company ->", mobileVendor ) // Apple
console.log( "Model ->", mobileModel ) // iPhone
return (
<>
<div className={`App ${mobileVendor} ${mobileModel}`}> // CSS Class
Detect this way.
Not really what I'm looking for. I think this is an issue in the documentation being totally incorrect.
What does work:
import { isAndroid, isChrome } from 'react-device-detect';
if (isAndroid && isChrome) {
do thing that is specific to Chrome on Android
}
@ericblade You're right, it's a documentation issue. It's just a type, not a selector, you can compare it, for example, with osName, like this:
import { osName, OsTypes } from 'react-device-detect'
if (osName === OsTypes.Android) {
// do something
}
Using it like it described in documentation right now is wrong, I will fix it in a future release. Thank you.
That is kind of what I thought, but I poked around through the code and decided there was a lot of magic involved that I didn't have time to understand, and I noticed "isAndroid" which is exactly what I was going for anyway (have a specific issue that only affects Chrome on Android... sigh)