
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
use-device-hook
Advanced tools
A simple and powerful React hook that detects various properties of the user's device, including the device type, operating system, screen resolution, network status, browser, preferred language, color scheme, and more. Perfect for responsive design and creating personalized user experiences.
To install the useDeviceHook package, run the following command:
npm install use-device-hook
or
yarn add use-device-hook
import React from "react";
import { useDevice } from "use-device-hook";
function Mycomponent() {
const { device, os, screenResolution, isOnline, browser, language, theme, timezone } = useDevice();
return (
<div>
<p>Device: {device}</p>
<p>OS: {os}</p>
<p>Screen Resolution: {screenResolution.width} x {screenResolution.height}</p>
<p>Network Status: {isOnline ? "Online" : "Offline"}</p>
<p>Browser: {browser}</p>
<p>Language: {language}</p>
<p>Theme: {theme}</p>
<p>Timezone: {timezone}</p>
</div>
);
}
export default Mycomponent;
The useDevice hook returns an object containing the following values:
The hook also listens for window resize events and dynamically updates the screen resolution, so you can always have the most up-to-date value for responsive design purposes.
const { screenResolution } = useDevice();
console.log(`Current screen resolution: ${screenResolution.width} x ${screenResolution.height}`);
The hook detects whether the user is online or offline by listening to the online and offline events.
const { isOnline } = useDevice();
console.log(`User is currently ${isOnline ? "online" : "offline"}`);
The hook automatically detects the user's browser and preferred language from the navigator object.
const { browser, language } = useDevice();
console.log(`User is using ${browser} and prefers the language ${language}`);
The hook detects the user’s preferred color scheme (light or dark mode) and updates dynamically if the user changes their system preference.
const { theme } = useDevice();
console.log(`User prefers the ${theme} color scheme`);
The hook also detects the user's timezone based on the system's locale settings.
const { timezone } = useDevice();
console.log(`User's timezone is ${timezone}`);
The hook exposes the following values:
const {
device, // "mobile" | "tablet" | "desktop"
os, // "Windows" | "macOS" | "Android" | "iOS" | "Linux" | "Unknown"
screenResolution, // { width: number, height: number }
isOnline, // boolean
browser, // string (e.g., "Chrome", "Firefox", etc.)
language, // string (e.g., "en-US")
theme, // "light" | "dark"
timezone // string (e.g., "America/New_York")
} = useDevice();
This project is licensed under the MIT License.
Feel free to submit issues, feature requests, and pull requests! All contributions are welcome.
If you encounter any issues or bugs with the hook, please feel free to open an issue in the GitHub repository. Make sure to check the console for any errors or warnings related to usage.
FAQs
A simple React hook to detect the device type and OS.
We found that use-device-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.