Napolean Paced Mischeviously

    react-ua

    3.0.0 • Public • Published

    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

    Install

    npm i react-ua

    DownloadsWeekly Downloads

    117

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    316 kB

    Total Files

    11

    Last publish

    Collaborators

    • antonybudianto