useDevice
Detect the device type with some boolean values.
Return Values
Name | Type | Description |
---|---|---|
device | String | device type (desktop , mobile ...). |
isDesktop | Boolean | the device is a desktop or not. |
isMobile | Boolean | the device is a mobile or not. |
isTablet | Boolean | the device is a tablet or not (this also leads isMobile to be true). |
isSmartTV | Boolean | the device is a smart TV or not. |
isConsole | Boolean | the device is a console device or not (PlayStation, Xbox, Nintendo...). |
Example Usage
tsx
import { useDevice } from 'react-pre-hooks';
export default function Example() {
const { device } = useDevice();
return (
<main>
<p>
Current device is <span>{device}</span>.
</p>
</main>
);
}
import { useDevice } from 'react-pre-hooks';
export default function Example() {
const { device } = useDevice();
return (
<main>
<p>
Current device is <span>{device}</span>.
</p>
</main>
);
}