React User Agent
Install
npm
npm i --save react-useragent
or yarn
yarn add react-useragent
Importing
ES6
;
ES5 (CommonJS)
const UserAgent = ;
ES5 (UMD Build)
<!-- make sure and also include react and react-dom -->
var UserAgent = ReactUserAgentUserAgent;
Usage
Children Function
;; { <div> <UserAgent> { return uamobile ? <input type="date" /> : <input type="text" />>; } </UserAgent> </div> } ;
Render Prop
;; { <div> <UserAgent render= { return uamobile ? <input type="date" /> : <input type="text" />>; } /> </div> } ;
HOC
;; { <div> thispropsuamobile ? <input type="date" /> : <input type="text" /> </div>; } 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.