Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-context

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-context

Helpful Properties with React Context

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
322
increased by10.65%
Maintainers
1
Weekly downloads
 
Created
Source

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(){

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

    return(
      <a href={ downloadLink }>Download App</div>
    )
  }
});

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 <div>Root</div>
  }
});

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();

Keywords

FAQs

Package last updated on 02 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc