UNPKG

react-redux-restate

Version:

Reform, rewire, restate redux state, or even states

34 lines (25 loc) 723 B
import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { createProvider } from 'react-redux'; const reprovide = (newName, oldName = 'store') => { const storeKey = oldName; const restateKey = newName; const Provider = createProvider(restateKey); class Reprovider extends Component { static contextTypes = { [storeKey]: PropTypes.any, }; static propTypes = { children: PropTypes.node, }; constructor(props, context) { super(); this.store = props[storeKey] || context[storeKey]; } render() { return <Provider store={this.store}>{this.props.children}</Provider>; } } return Reprovider; }; export default reprovide;