Skip to content

JJoGeon/opgg-use-device-detector

Repository files navigation

opgg-use-device-detector

Check your device when you have anything to change on your PC or mobile.

❤️ it? ⭐️ it on GitHub

opgg-use-device-detector basically provides physical device data and logical device data.

  • Physical device: Device information that was accessed when the site was first accessed.
  • Logical device: Device information that changes internally when changing the current state to an arbitrary device.

Requirement

To use opgg-use-device-detector, you must use react@16.8.0 or greater which includes Hooks.

Installation

$ npm i opgg-use-device-detector

Usage

import useDeviceDetector from 'opgg-use-device-detector'

const deviceDetector = useDeviceDetector(initialState, deviceDetectorConfig)

Parameters

You pass useDeviceDetector an initialState and an optional deviceDetectorConfig object. The configuration object may contain the following keys.

Key Description
onChange [Comming Soon!]
storageKey A string that will be used by the storageProvider to persist the logical device data. If you specify a value of null, nothing will be persisted. Default=logicalDeviceData.
storageProvider A storage provider. Default = localStorage. You will generally never need to change this value.

This version does not provide local storage usage and onChange functions.

2022.03.13
[BugFix] - Fix the bug where the physical device data is initialized.

2022.03.10
[Update] - Contributor setting.
[Ongoing] - Add window.navigator.userAgent parser.
[Update] - Remove the defense and lighten the project.

2022.03.07
[Update] - Remove device model and brand (Fixing the bug.)
[Update] - Add function version.1 (use local storage)

Return object

A deviceDetector object is returned with the following properties.

Key Description
physicalDevice Device information on the first visit.
logicalDevice Logically changed device information.
isMobile Check current state. (true = 'smartphone' / false = 'desktop')
toggle() A function that allows you to toggle 'smartphone' or 'desktop'.

License

MIT Licensed

Contributors


JJoGeon

About

Check your device when you have anything to change on your PC or mobile.

Topics

Resources

Stars

Watchers

Forks