2.0.0 • Published 7 years ago

connect-to-context v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

connect-to-context

React: Context -> Props

Example

import connectToContext from 'connect-to-context'

const Test1 = connectToContext('primaryId')(TestRaw);

const Test2 = connectToContext(['primaryId', 'testId'])(TestRaw);

const Test3 = connectToContext('primaryId', (context) => ({
    identityFieldName : 'primaryId',
    experimentInputs  : {primaryId : context.primaryId}
}))(TestRaw);

class Provider extends React.Component {
    static childContextTypes = {
        primaryId: React.PropTypes.any,
        testId: React.PropTypes.any,
    };

    getChildContext() {
        return {
            primaryId: this.props.primaryId,
            testId: this.props.testId,
        }
    }

    render() {
        return (
            <div>
                {this.props.children}
            </div>
        );
    }
}

ReactDOMServer.renderToStaticMarkup(
    <Provider primaryId = {primaryId} testId = {testId}>
        <Test1/>
        <Test2/>
        <Test3/>
    </Provider>
)
2.0.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago