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 = /* * In your browser's chrome devtools console you should see * > IS BROWSER: 👍 * > IS SERVER: 👎 * * AND, in your terminal where your server is running you should see * > IS BROWSER: 👎 * > IS SERVER: 👍 */ console console console return <> Is in browser? isBrowser ? '👍' : '👎' <br /> Is on server? isServer ? '👍' : '👎' <br /> Is react native? isNative ? '👍' : '👎' </> )}
Options
const isBrowser isServer isNative device // 'server', 'browser', or 'native' canUseWorkers canUseEventListeners canUseViewport} =