ru
react-ua
npm i react-ua
ru

react-ua

📱React User Agent Component, Hook, and HOC. SSR-ready, full UT, using new React Context and Hooks API

by Antony Budianto

3.0.0 (see all)License:MITTypeScript:Not FoundCategories:React User Agent Parsing
npm i react-ua
Readme

react-ua

npm version Build Status

React User Agent Component and Provider, SSR-ready, using new React Context API

Requirement

  • React 16.8.0

Features

Try it live at StackBlitz

import React from 'react';
import { UserAgentProvider, useUserAgent } from 'react-ua';

const CompWithHooks = () => {
  const ua = useUserAgent();
  return <div>OS: {ua.os.name}</div>;
};

const CompWithHoc = withUserAgent(({ ua }) => <div>OS: {ua.os.name}</div>);

const App = () => (
  <UserAgentProvider>
    <CompWithHoc />
    <CompWithHooks />
  </UserAgentProvider>
);

ReactDOM.render(<App />, document.getElementById('#root'));

// SSR
const el = (
  <UserAgentProvider value={request.headers['user-agent']}>
    <Comp />
    <CompWithHoc />
  </UserAgentProvider>
);

ReactDOMServer.renderToString(el);

License

MIT

Downloads/wk

89

GitHub Stars

18

LAST COMMIT

1mo ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
3.0.0
latest
1mo ago
No tutorials found
Add a tutorial