Skip to content

Instantly share code, notes, and snippets.

@gribnoysup
Last active March 1, 2017 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gribnoysup/a30eff6d44637bf2158df9fe48da0086 to your computer and use it in GitHub Desktop.
Save gribnoysup/a30eff6d44637bf2158df9fe48da0086 to your computer and use it in GitHub Desktop.
import React from 'react'
const {oneOf, node, func, oneOfType} = React.PropTypes
const isMobile = /Mobi/.test(window.navigator.userAgent || '')
const device = {
mobile: isMobile,
desktop: !isMobile
}
export default function DetectDevice({is, children}) {
const check = device[is]
return typeof children === 'function' ?
children(check) : (
check ? children : null
)
}
DetectDevice.propTypes = {
is: oneOf(['desktop', 'mobile']),
children: oneOfType([node, func])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment