react-context

by casesandberg

casesandberg / react-context

:shipit: Helpful Properties with React Context

197 Stars 9 Forks Last release: Not found MIT License 70 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

React Context

  • Engagement Properties - AdBlock and Focus
  • Display Properties - Density, Scroll, Width and Height
  • Device Properties - Language, OS, Browser and Browser Version
var React = require('react');
var context = require('react-context');

var Component = React.createClass({

// subscribe to all the contextTypes contextTypes: context.subscribe(['os']),

render() { var downloadLink;

switch (this.state.os) {
  case 'Windows':
    downloadLink = 'http://some.url/downloads/App.exe';
    break;
  case 'Mac':
    downloadLink = 'http://some.url/downloads/App.app';
    break;
  case 'Android':
    downloadLink = 'https://play.google.com/store/apps/details?id=com.app.some';
    break;
  case 'iOS':
    downloadLink = 'https://itunes.apple.com/us/app/someapp/id12345678';
    break;
  default:
    downloadLink = 'http://some.url/downloads/';
    break;
}

return <a href="%7B" downloadlink>Download App

} });

Installation & Usage

npm install react-context --save

Wrap Root

Wrap your top-most component with

react-context
.
var React = require('react');
var context = require('react-context');

var Root = React.createClass({ render() { return

Root
} });

module.exports = context(Root);

Set Types

Pass it an array of types you want to subscribe to, or call it with no arguments to subscribe to all of them.

// Subscribe to scroll and adBlock
Child.contextTypes = context.subscribe(['scroll', 'adBlock']);

// Subscribe to every context Child.contextTypes = context.subscribe();

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.