Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "react-ua", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "React User Agent component and provider with new React Context API", | ||
@@ -22,6 +22,3 @@ "main": "dist/react-ua.js", | ||
"jest": { | ||
"testEnvironment": "jsdom", | ||
"setupFiles": [ | ||
"jest-localstorage-mock" | ||
] | ||
"testEnvironment": "jsdom" | ||
}, | ||
@@ -34,3 +31,4 @@ "repository": { | ||
"react", | ||
"localstorage" | ||
"user agent", | ||
"ua-parser-js" | ||
], | ||
@@ -37,0 +35,0 @@ "author": "Antony Budianto <antonybudianto@gmail.com>", |
@@ -6,4 +6,10 @@ # react-ua | ||
User Agent Component and Provider, wrapper for [ua-parser-js](https://github.com/faisalman/ua-parser-js), SSR-ready, using new React Context API | ||
React User Agent Component and Provider, SSR-ready, using new React Context API | ||
## Features | ||
- Wrapper for [ua-parser-js](https://github.com/faisalman/ua-parser-js) | ||
- Using new React [Context API](https://reactjs.org/docs/context.html) | ||
- SSR-ready | ||
> Try it [live at StackBlitz](https://stackblitz.com/edit/demo-react-ua) | ||
@@ -15,2 +21,8 @@ | ||
class App extends Component { | ||
render() { | ||
return <UserAgent>{ua => <div>OS: {ua.os.name}</div>}</UserAgent>; | ||
} | ||
} | ||
class Home extends Component { | ||
@@ -22,4 +34,4 @@ state = { | ||
return ( | ||
<UserAgentProvider value={window.navigator.userAgent}> | ||
<UserAgent>{ua => <div>OS: {ua.os.name}</div>}</UserAgent> | ||
<UserAgentProvider> | ||
<App /> | ||
</UserAgentProvider> | ||
@@ -29,2 +41,11 @@ ); | ||
} | ||
// SSR | ||
const el = ( | ||
<UserAgentProvider value={request.headers['user-agent']}> | ||
<App /> | ||
</UserAgentProvider> | ||
); | ||
renderToString(el); | ||
``` | ||
@@ -31,0 +52,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
308806
52
0