Need help with react-context?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

casesandberg
197 Stars 9 Forks MIT License 70 Commits 1 Opened issues

Description

:shipit: Helpful Properties with React Context

Services available

!
?

Need anything else?

Contributors list

# 2,425
JavaScr...
React
CSS
inline-...
56 commits
# 89,018
adblock...
Webpack
Rails
ESLint
2 commits
# 8,750
JavaScr...
Bash
unix
React
1 commit
# 12,413
jupyter...
js
css-fra...
SQL
1 commit

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.