Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-device-detect

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-device-detect

Detect device type and render your component according to it

  • 2.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
953K
increased by8.81%
Maintainers
1
Weekly downloads
 
Created

What is react-device-detect?

The react-device-detect package is a tool for detecting device types and browser environments in a React application. It provides a set of hooks and components that allow developers to render content conditionally based on the user's device type, operating system, browser, and other device-specific characteristics.

What are react-device-detect's main functionalities?

Device Type Detection

Detects the type of device (mobile, tablet, desktop) and allows you to render content conditionally based on the device type.

import { isMobile, isTablet, isDesktop } from 'react-device-detect';

function MyComponent() {
  return (
    <div>
      {isMobile && <p>This is a mobile device.</p>}
      {isTablet && <p>This is a tablet device.</p>}
      {isDesktop && <p>This is a desktop device.</p>}
    </div>
  );
}

Browser Detection

Determines the browser being used (e.g., Chrome, Firefox) and enables conditional rendering of components or content for specific browsers.

import { isChrome, isFirefox } from 'react-device-detect';

function MyComponent() {
  return (
    <div>
      {isChrome && <p>This is viewed in Chrome.</p>}
      {isFirefox && <p>This is viewed in Firefox.</p>}
    </div>
  );
}

Operating System Detection

Identifies the operating system of the user's device (e.g., Android, iOS) and allows for OS-specific content or functionality.

import { isAndroid, isIOS } from 'react-device-detect';

function MyComponent() {
  return (
    <div>
      {isAndroid && <p>This is an Android device.</p>}
      {isIOS && <p>This is an iOS device.</p>}
    </div>
  );
}

Custom Hooks

Provides custom hooks that return an object with device detection booleans, allowing for more dynamic and custom implementations.

import { useDeviceDetect } from 'react-device-detect';

function MyComponent() {
  const { isMobile, isDesktop } = useDeviceDetect();
  return (
    <div>
      {isMobile && <p>Content for mobile</p>}
      {isDesktop && <p>Content for desktop</p>}
    </div>
  );
}

Other packages similar to react-device-detect

Keywords

FAQs

Package last updated on 08 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc