react-mixout-pass-context
Pass context down the tree in various ways
Last updated 2 years ago by alitaheri .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-mixout-pass-context 
SYNC missed versions from official npm registry.

React Mixout - Pass Context

npm Build Status

For a full description of what this is please refer to the main README file of this project.

This mixout allows you to easily forward props as context.

Installation

You can install this package with the following command:

npm install react-mixout-pass-context

Example

import React from 'react';
import mixout from 'react-mixout';
import passContext from 'react-mixout-pass-context';

class MyComponent extends React.Component {
  static contextTypes = {
    color: React.PropTypes.string,
  };

  render() {
    return <span style={{color: this.context.color}}>Hello</span>;
  }
}

// Although directly using context when props could do doesn't make sense,
// but you get the point. :D 
export default mixout(passContext('color', ({r, g, b}) => `rgb(${r},${g},${b})`))(MyComponent);

API Reference

passContext

function passContext(name: string, builder: (ownProps: any) => any): Injector;
  • name: The name context to be passed down the tree.
  • builder: Calculates the context value from the component props.

Typings

The typescript type definitions are also available and are installed via npm.

License

This project is licensed under the MIT license.

Current Tags

  • 0.5.7                                ...           latest (2 years ago)

8 Versions

  • 0.5.7                                ...           2 years ago
  • 0.5.6                                ...           3 years ago
  • 0.5.5                                ...           3 years ago
  • 0.5.4                                ...           3 years ago
  • 0.5.2                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 8
Last Month 1
Dependencies (2)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |