device-type-detector
v1.1.4
Published
A simple npm package to detect device type based on user agent and screen size.
Downloads
27
Maintainers
Readme
device-type-detector
React module to detect OS / Browser / Device
Install
NPM
$ npm install device-type-detector --save
Yarn
$ yarn add device-type-detector
How to use in React
import React, { useEffect, useState } from 'react';
import { getDeviceType } from 'device-detector';
const App = () => {
const [deviceType, setDeviceType] = useState('');
useEffect(() => {
const type = getDeviceType();
setDeviceType(type);
}, []);
return (
<div>
<h1>Device Detector</h1>
<p>Your device type is: {deviceType}</p>
</div>
);
};
export default App;
How to use in Javascript
const deviceType = getDeviceType();
console.log(deviceType); // Outputs: 'mobile', 'tablet', 'desktop', or 'unknown'