All Projects → jonstuebe → react-useragent

jonstuebe / react-useragent

Licence: other
Higher order component to add user agent information to your react components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-useragent

React Bps
🔱 Create breakpoints to your component props
Stars: ✭ 64 (+392.31%)
Mutual labels:  hoc
Next Nprogress
Next.js HOC to integrate NProgress inside your app
Stars: ✭ 145 (+1015.38%)
Mutual labels:  hoc
Tubular React
Material UI table with local or remote data-source. Featuring filtering, sorting, free-text search, export to CSV locally, and aggregations.
Stars: ✭ 202 (+1453.85%)
Mutual labels:  hoc
Awesome React Render Props
Awesome list of React components with render props
Stars: ✭ 1,304 (+9930.77%)
Mutual labels:  hoc
React Spatial Navigation
HOC-based Spatial Navigation (key navigation) solution for React
Stars: ✭ 128 (+884.62%)
Mutual labels:  hoc
Neoform
✅ React form state management and validation
Stars: ✭ 162 (+1146.15%)
Mutual labels:  hoc
Kanban React
The Kanban Application with multiple backend languages.
Stars: ✭ 15 (+15.38%)
Mutual labels:  hoc
react-app-loader
Production ready library for handling Microfrontends
Stars: ✭ 75 (+476.92%)
Mutual labels:  hoc
React Onclickoutside
An onClickOutside wrapper for React components
Stars: ✭ 1,736 (+13253.85%)
Mutual labels:  hoc
Redux Auth Wrapper
A React Higher Order Component (HOC) for handling Authentication and Authorization with Routing and Redux
Stars: ✭ 2,175 (+16630.77%)
Mutual labels:  hoc
Flagged
Feature Flags for React made easy with hooks, HOC and Render Props
Stars: ✭ 97 (+646.15%)
Mutual labels:  hoc
Rx React Container
Use RxJS in React components, via HOC or Hook
Stars: ✭ 105 (+707.69%)
Mutual labels:  hoc
React Nprogress
⌛️ A React primitive for building slim progress bars.
Stars: ✭ 173 (+1230.77%)
Mutual labels:  hoc
Incompose
A inferno utility belt for function components and higher-order components
Stars: ✭ 76 (+484.62%)
Mutual labels:  hoc
Next Ga
Next.js HOC to integrate Google Analytics on every page change
Stars: ✭ 228 (+1653.85%)
Mutual labels:  hoc
Withobservables
HOC (Higher-Order Component) for connecting RxJS Observables to React Components
Stars: ✭ 41 (+215.38%)
Mutual labels:  hoc
Hocs
🍱 Higher-Order Components for React
Stars: ✭ 1,784 (+13623.08%)
Mutual labels:  hoc
rrx
⚛️ Minimal React router using higher order components
Stars: ✭ 69 (+430.77%)
Mutual labels:  hoc
Escape From Callback Mountain
Example Project & Guide for mastering Promises in Node/JavaScript. Feat. proposed 'Functional River' pattern
Stars: ✭ 249 (+1815.38%)
Mutual labels:  hoc
React With Direction
Components to provide and consume RTL or LTR direction in React
Stars: ✭ 176 (+1253.85%)
Mutual labels:  hoc

React User Agent

Install

npm

npm i --save react-useragent

or yarn

yarn add react-useragent

Importing

ES6

import { UserAgent } from "react-useragent";

ES5 (CommonJS)

const { UserAgent } = require("react-useragent");

ES5 (UMD Build)

<head>
  <!-- make sure and also include react and react-dom -->
  <script src="https://unpkg.com/[email protected]/mobile-detect.js" />
  <script src="https://unpkg.com/[email protected]/lib/index.js" />
</head>
var UserAgent = ReactUserAgent.UserAgent;

Usage

Children Function

import React, { Component } from 'react';
import { UserAgent } from 'react-useragent';

class App extends Component {
  render() {
    <div>
      <UserAgent>
        {({ ua }) => {
          return ua.mobile ? <input type="date" /> : <input type="text" />>;
        }}
      </UserAgent>
    </div>
  }
}

export default App;

Render Prop

import React, { Component } from 'react';
import { UserAgent } from 'react-useragent';

class App extends Component {
  render() {
    <div>
      <UserAgent render={({ ua }) => {
        return ua.mobile ? <input type="date" /> : <input type="text" />>;
      }} />
    </div>
  }
}

export default App;

HOC

import React, { Component } from "react";
import { withUserAgent } from "react-useragent";

class App extends Component {
  render() {
    <div>
      {this.props.ua.mobile ? <input type="date" /> : <input type="text" />}
    </div>;
  }
}

export default withUserAgent(App);

API

This utility uses mobile-detect for user agent parsing. The following object is exposed to the component through props/args (depending on the usage). The key "md" is the actual mobile-detect constructor and is available to call any mobile-detect methods that are not included by default.

{
  "mobile": null,
  "phone": null,
  "tablet": null,
  "os": null,
  "md": {
    "ua":
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36",
    "_cache": {
      "phone": null,
      "tablet": null,
      "mobile": null,
      "os": null
    },
    "maxPhoneWidth": 600
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].