/device-detector

Primary LanguageTypeScriptISC LicenseISC

device-type-detector

React module to detect OS / Browser / Device

npm version GitHub issues GitHub license npm npm npm

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'

License

MIT License