useDeviceOptions
Need to know when you're on the server, in the browser or in react native in your components/hooks? This simple hook makes it easy. 🔥
Features
- SSR (server side rendering) support
- TypeScript support
- Zero dependencies
- React Native support
Installation
yarn add use-device-options or npm i -S use-device-options
Usage
import useDeviceOptions from 'use-device-options'
const App = () => {
var { isBrowser, isServer, isNative } = useDeviceOptions()
console.log('IS BROWSER: ', isBrowser ? '👍' : '👎')
console.log('IS SERVER: ', isServer ? '👍' : '👎')
console.log('IS NATIVE: ', isNative ? '👍' : '👎')
return (
<>
Is in browser? {isBrowser ? '👍' : '👎'}
<br />
Is on server? {isServer ? '👍' : '👎'}
<br />
Is react native? {isNative ? '👍' : '👎'}
</>
)
}
Options
const {
isBrowser,
isServer,
isNative,
device,
canUseWorkers,
canUseEventListeners,
canUseViewport,
} = useDeviceOptions()