Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Device Detector
Official extension
Version: 0.2.6
Latest version: 0.2.6

Use this app's HOC or hook to find out current device's viewport size.

Usage

useDevice

Returns an object with the format of DeviceInfo defined as:


_10
interface DeviceInfo {
_10
device: Device
_10
isMobile: boolean
_10
}
_10
_10
enum Device {
_10
phone = 'phone',
_10
tablet = 'tablet',
_10
desktop = 'desktop',
_10
}


_10
import { useDevice } from 'vtex.device-detector'
_10
const MyComponent = props => {
_10
const { isMobile } = useDevice()
_10
if (isMobile) {
_10
// is phone or tablet!
_10
}
_10
return ...
_10
}

or


_10
import { useDevice } from 'vtex.device-detector'
_10
const MyComponent = props => {
_10
const { device } = useDevice()
_10
if (device === 'tablet') {
_10
//is tablet!
_10
}
_10
return ...
_10
}

withDevice

It is a HOC, it injects two props (isMobile and device) into your component's props:


_10
type WithDeviceProps = Props & {
_10
isMobile: boolean
_10
device: Device
_10
}
_10
enum Device {
_10
phone = 'phone',
_10
tablet = 'tablet',
_10
desktop = 'desktop',
_10
}


_10
import { withDevice } from 'vtex.device-detector'
_10
const MyComponent = props => {
_10
if (props.isMobile) {
_10
// is phone or tablet!
_10
}
_10
return ...
_10
}
_10
_10
export default withDevice(MyComponent)

or


_10
import { useDevice } from 'vtex.device-detector'
_10
const MyComponent = props => {
_10
if (props.device === 'tablet') {
_10
//is tablet!
_10
}
_10
return ...
_10
}
_10
_10
export default withDevice(MyComponent)

See also
VTEX App Store
VTEX IO Apps