Skip to content

useDevice

Detect the device type with some boolean values.

Return Values

NameTypeDescription
deviceStringdevice type (desktop, mobile...).
isDesktopBooleanthe device is a desktop or not.
isMobileBooleanthe device is a mobile or not.
isTabletBooleanthe device is a tablet or not (this also leads isMobile to be true).
isSmartTVBooleanthe device is a smart TV or not.
isConsoleBooleanthe device is a console device or not (PlayStation, Xbox, Nintendo...).

Example Usage

tsx
import { useDevice } from 'react-pre-hooks';

export default function Example() {
  const { device } = useDevice();

  return (
    <main>
      <p>
        Current device is <span>{device}</span>.
      </p>
    </main>
  );
}
import { useDevice } from 'react-pre-hooks';

export default function Example() {
  const { device } = useDevice();

  return (
    <main>
      <p>
        Current device is <span>{device}</span>.
      </p>
    </main>
  );
}

Released under the MIT License.