Skip to content

nishantshah977/next-device-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Device Type Detector for React and Next.js

NodeJS React Next JS

Project Links:

NPM GitHub

Installation

npm i next-device-detection

Usage

It works by checking width of window. (Mobile, Tablet and Desktop)

import useDeviceDetector from "next-device-detection";

function MyComponent() {
  const device = useDeviceDetector();

  return (
    <div>
      {device.isMobile && <p>Mobile device detected!</p>}
      {device.isTablet && <p>Tablet device detected!</p>}
      {device.isDesktop && <p>Desktop device detected!</p>}
    </div>
  );
}

export default MyComponent;

Detect if detection is complete

if (!device.detected) {
  // Show loading or return null
}

Changelog

v1.1.0:

  • useLayoutEffect hook instead of useEffect.
  • New property to track if detection is complete.

v1.0.1:

  • Proper Docs Added

Contributing

Help to improve this project by a PR. Feel free to open issue or submit an PR.

About

Detect device type (Mobile, Tablet, Desktop). Use in react and Next.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published