summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/components/ContextProvider.js
blob: 86c8d41df00ed29f9f12e485728fc5d4df9e9bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const React = require('react');
const { Provider } = require('react-redux');

const ContextShape = require('../shapes/Context');

/**
 * React component to provide a GitBook context to children components.
 */

const ContextProvider = React.createClass({
    propTypes: {
        context: ContextShape.isRequired,
        children: React.PropTypes.node
    },

    childContextTypes: {
        gitbook: ContextShape
    },

    getChildContext() {
        const { context } = this.props;

        return {
            gitbook: context
        };
    },

    render() {
        const { context, children } = this.props;
        return <Provider store={context.store}>{children}</Provider>;
    }
});

module.exports = ContextProvider;