https://github.com/antonybudianto/react-ua
📱React User Agent Component, Hook, and HOC. SSR-ready, full UT, using new React Context and Hooks API
https://github.com/antonybudianto/react-ua
hooks react reactjs ssr user-agent user-agent-parser
Last synced: 12 months ago
JSON representation
📱React User Agent Component, Hook, and HOC. SSR-ready, full UT, using new React Context and Hooks API
- Host: GitHub
- URL: https://github.com/antonybudianto/react-ua
- Owner: antonybudianto
- License: mit
- Created: 2018-12-01T09:23:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T01:46:14.000Z (about 3 years ago)
- Last Synced: 2025-03-15T12:06:04.444Z (12 months ago)
- Topics: hooks, react, reactjs, ssr, user-agent, user-agent-parser
- Language: TypeScript
- Homepage:
- Size: 363 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-ua
[](https://badge.fury.io/js/react-ua)
[](https://travis-ci.org/antonybudianto/react-ua)
React User Agent Component and Provider, SSR-ready, using new React Context API
## Requirement
- React 16.8.0
## Features
- Wrapper for [ua-parser-js](https://github.com/faisalman/ua-parser-js)
- Using new React [Hooks API](https://reactjs.org/docs/hooks-faq.html)
- Using new React [Context API](https://reactjs.org/docs/context.html)
- SSR-ready
- Unit-tested
> Try it [live at StackBlitz](https://stackblitz.com/edit/demo-react-ua)
```js
import React from 'react';
import { UserAgentProvider, useUserAgent } from 'react-ua';
const Comp = () => {
const ua = useUserAgent();
return
OS: {ua.os.name};
};
const App = () => (
);
ReactDOM.render(, document.getElementById('#root'));
// SSR
const el = (
);
ReactDOMServer.renderToString(el);
```
## HOC (deprecated)
```tsx
import { withUserAgent } from 'react-ua/hoc';
const CompWithHoc = withUserAgent(({ ua }) =>
OS: {ua.os.name});
const App = () => (
);
```
## License
MIT