1.0.18 • Published 6 years ago

usedevice v1.0.18

Weekly downloads
10
License
MIT
Repository
github
Last release
6 years ago

useDevice

React Hook for detect device properties

Install

npm install -S usedevice

Usage

import useDevice from 'usedevice';

const Component = () => {
  const device = useDevice();

  return (
    <section>...</section>
  );
};

Device wil have the following properties

{
  browser: "Chrome",
  device: "desktop",
  height: 438,
  isIE: false,
  isMobileAgent: false,
  isOrientationCapable: true,
  isTouch: false,
  orientation: "landscape",
  os: "Mac OS X",
  screenSize: "desktop",
  version: "10_11_5",
  width: 1292,
}

In every resize the hook will execute and return a new object with the new properties

Breakpoints

You can pass an array of breakpoints to the hook

import useDevice from 'usedevice';

const breakpoints = [
  {name: 'miniphone', min: 0, max: 320},
  {name: 'phone', min: 320, max: 640},
  {name: 'tablet', min: 640, max: 1080},
  {name: 'desktop', min: 1080, max: Infinity},
];

const Component = () => {
  const device = useDevice(breakpoints);

  return (
    <section>...</section>
  );
};

In the constant device you will receive the prop breakpoint with the name of the breakpoint matching, if multiple breakpoints match the name is from the first match.

{
  breakpoint: 'desktop'
  width: 1292,
}

{
  breakpoint: 'phone'
  width: 540,
}
1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago