1.1.0 • Published 4 years ago

react-config-hooks v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-config-hooks

Deliver experiences best suited to a user's OS, device type, browser, and other things

NPMJavaScript Style Guide License: MIT Inline docs contributions welcome

This is a suite of React Hooks and utilities for adaptive loading based on a user's:

  • Operating System
  • Browser
  • Configuration

Objective

Make it easier for developer to target different devices based on their configuration. It can be used to check different settings related to config in order to deliver best experiences to user.

Install

npm install --save react-config-hooks

Usage

Operating System

import { useOS } from 'react-config-hooks'

const [ os,isWin,isMac,isUnix,isLinux,isWinMob,isAndroid,isiOS ] = useOS()
 
ValueReturnsReturn type
osReturns the name of OSString
isWinReturns true if OS is Windows and vice versaboolean
isMacReturns true if OS is Mac and vice versaboolean
isUnixReturns true if OS is Unix and vice versaboolean
isLinuxReturns true if OS is Linux and vice versaboolean
isWinMobReturns true if OS is Windows Mobile and vice versaboolean
isAndroidReturns true if OS is Android and vice versaboolean
isiOSReturns true if OS is iOS and vice versaboolean

 


Browser

import { useBrowser } from 'react-config-hooks'

const [ browser,isChrome,isFirefox,isIE,isEdge,isSafari,isOpera,isYandex ] = useBrowser()
 
ValueReturnsReturn type
browserReturns the name of browserString
isChromeReturns true if browser is Chrome and vice versaboolean
isFirefoxReturns true if browser is Firefox and vice versaboolean
isIEReturns true if browser is IE and vice versaboolean
isEdgeReturns true if browser is Edge and vice versaboolean
isSafariReturns true if browser is Safari and vice versaboolean
isOperaReturns true if browser is Opera and vice versaboolean
isYandexReturns true if browser is Yandex and vice versaboolean

 


Config

import { useConfig } from 'react-config-hooks'

const [ deviceConfig,isCookieEnabled,isOnLine,knownLangs,prefLang,isJavaEnabled ] = useConfig()
 
ValueReturnsReturn type
deviceConfigReturns the different properties (isCookieEnabled,isOnLine,knownLangs,prefLang,isJavaEnabled) related to configArrays of objects
isCookieEnabledReturns true if cookie is enabled and vice versaboolean
isOnLineReturns true if user is online and vice versaboolean
knownLangsReturns an array representing the languages known to the user, by order of preferencearray
prefLangReturns an string representing the preferred language of the user, usually the language of the browser UI. The null value is returned when this is unknown.String
isJavaEnabledReturns true if Java is enabled and vice versaboolean

 


License

MIT © dev-saeed