Gathering detailed insights and metrics for bb-react-device-detect
Gathering detailed insights and metrics for bb-react-device-detect
npm install bb-react-device-detect
Typescript
Module System
Node Version
NPM Version
68.4
Supply Chain
94.1
Quality
74.7
Maintenance
100
Vulnerability
100
License
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
262
Last Day
1
Last Week
2
Last Month
11
Last Year
79
Latest Version
1.6.1
Package Id
bb-react-device-detect@1.6.1
Unpacked Size
80.03 kB
Size
17.94 kB
File Count
13
NPM Version
6.14.15
Node Version
14.17.6
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
175%
11
Compared to previous month
Last Year
6.8%
79
Compared to previous year
Detect device, and render view according to detected device type.
To install, you can use npm or yarn:
npm install react-device-detect --save
or
yarn add react-device-detect
Example:
1import { 2 BrowserView, 3 MobileView, 4 isBrowser, 5 isMobile 6} from "react-device-detect";
1<BrowserView> 2 <h1> This is rendered only in browser </h1> 3</BrowserView> 4<MobileView> 5 <h1> This is rendered only on mobile </h1> 6</MobileView>
if you don't need a view, you can use isMobile
for conditional rendering
1import {isMobile} from 'react-device-detect'; 2 3renderContent = () => { 4 if (isMobile) { 5 return <div> This content is unavailable on mobile</div> 6 } 7 return <div> ...content </div> 8} 9 10render() { 11 return this.renderContent(); 12}
If you wan't to leave a message to specific browser (e.g IE), you can use isIE
selector
1import {isIE} from 'react-device-detect'; 2 3render() { 4 if (isIE) return <div> IE is not supported. Download Chrome/Opera/Firefox </div> 5 return ( 6 <div>...content</div> 7 ) 8}
If you want to render a view on specific device and with specific condition:
1import { browserName, CustomView } from 'react-device-detect'; 2 3render() { 4 return ( 5 <CustomView condition={browserName === "Chrome"}> 6 <div>...content</div> 7 </CustomView> 8 ) 9}
Yoa can style view component by passing class to viewClassName
prop
1<BrowserView viewClassName='custom-class'> 2 <p> View content </p> 3</BrowserView>
or you can pass inline styles to style
prop
1const styles = { 2 background: "red", 3 fontSize: "24px", 4 lineHeight: "2" 5};
1<BrowserView style={styles}> 2 <p> View content</p> 3</BrowserView>
prop | type | description |
---|---|---|
isMobile | bool | returns true if device type is mobile or tablet |
isMobileOnly | bool | returns true if device type is mobile |
isTablet | bool | returns true if device type is tablet |
isBrowser | bool | returns true if device type is browser |
isSmartTV | bool | returns true if device type is smarttv |
isWearable | bool | returns true if device type is wearable |
isConsole | bool | returns true if device type is console |
isAndroid | bool | returns true if os type is Android |
isWinPhone | bool | returns true if os type is Windows Phone |
isIOS | bool | returns true if os type is iOS |
isChrome | bool | returns true if browser is Chrome |
isFirefox | bool | returns true if browser is Firefox |
isSafari | bool | returns true if browser is Safari |
isOpera | bool | returns true if browser is Opera |
isIE | bool | returns true if browser is Internet Explorer |
isEdge | bool | returns true if browser is Edge |
isYandex | bool | returns true if browser is Yandex |
isChromium | bool | returns true if browser is Chromium |
isMobileSafari | bool | returns true if browser is Mobile Safari |
osVersion | string | returns os version (e.g 7 for Windows or 6 for Android ) |
osName | string | returns os name (e.g Windows , Android ) |
fullBrowserVersion | string | returns full browser version (e.g 65.0.3325.181 for Chrome ) |
browserVersion | string | returns browser major version (e.g 65 in Chrome or 9 in IE ) |
browserName | string | returns browser name |
mobileVendor | string | returns mobile device vendor (e.g LG , iPhone etc) |
mobileModel | string | returns mobile device model (e.g Nexus 5 ) |
engineName | string | returns browser engine name (e.g Gecko for FF or WebKit for Chrome) |
engineVersion | string | returns engine version |
getUA | string | returns user agent |
deviceDetect | function | return data object which includes all data about device (e.g version, engine, os etc.) |
Available views:
condition
prop which takes any expression which results into boolean (e.g browserName === 'Chrome')Each view accepts three props:
viewClassName
- to style the viewstyle
- to add inline styles to viewchildren
- to pass children to viewrenderWithFragment
- render with React.Fragment
instead of <div>
MIT
No vulnerabilities found.
No security vulnerabilities found.