@@ -18,31 +18,47 @@ export default function createProvider(React) {
1818 const storeShape = createStoreShape ( PropTypes ) ;
1919 const requireFunctionChild = isUsingOwnerContext ( React ) ;
2020
21- let didWarn = false ;
22- function warnAboutFunction ( ) {
23- if ( didWarn || requireFunctionChild ) {
21+ let didWarnAboutChild = false ;
22+ function warnAboutFunctionChild ( ) {
23+ if ( didWarnAboutChild || requireFunctionChild ) {
2424 return ;
2525 }
2626
27- didWarn = true ;
27+ didWarnAboutChild = true ;
2828 console . error ( // eslint-disable-line no-console
2929 'With React 0.14 and later versions, you no longer need to ' +
3030 'wrap <Provider> child into a function.'
3131 ) ;
3232 }
33- function warnAboutElement ( ) {
34- if ( didWarn || ! requireFunctionChild ) {
33+ function warnAboutElementChild ( ) {
34+ if ( didWarnAboutChild || ! requireFunctionChild ) {
3535 return ;
3636 }
3737
38- didWarn = true ;
38+ didWarnAboutChild = true ;
3939 console . error ( // eslint-disable-line no-console
4040 'With React 0.13, you need to ' +
4141 'wrap <Provider> child into a function. ' +
4242 'This restriction will be removed with React 0.14.'
4343 ) ;
4444 }
4545
46+ let didWarnAboutReceivingStore = false ;
47+ function warnAboutReceivingStore ( ) {
48+ if ( didWarnAboutReceivingStore ) {
49+ return ;
50+ }
51+
52+ didWarnAboutReceivingStore = true ;
53+ console . error ( // eslint-disable-line no-console
54+ '<Provider> does not support changing `store` on the fly. ' +
55+ 'It is most likely that you see this error because you updated to ' +
56+ 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
57+ 'automatically. See https://github.com/rackt/react-redux/releases/' +
58+ 'tag/v2.0.0 for the migration instructions.'
59+ ) ;
60+ }
61+
4662 return class Provider extends Component {
4763 static childContextTypes = {
4864 store : storeShape . isRequired
@@ -57,32 +73,31 @@ export default function createProvider(React) {
5773 } ;
5874
5975 getChildContext ( ) {
60- return { store : this . state . store } ;
76+ return { store : this . store } ;
6177 }
6278
6379 constructor ( props , context ) {
6480 super ( props , context ) ;
65- this . state = { store : props . store } ;
81+ this . store = props . store ;
6682 }
6783
6884 componentWillReceiveProps ( nextProps ) {
69- const { store } = this . state ;
85+ const { store } = this ;
7086 const { store : nextStore } = nextProps ;
7187
7288 if ( store !== nextStore ) {
73- const nextReducer = nextStore . getReducer ( ) ;
74- store . replaceReducer ( nextReducer ) ;
89+ warnAboutReceivingStore ( ) ;
7590 }
7691 }
7792
7893 render ( ) {
7994 let { children } = this . props ;
8095
8196 if ( typeof children === 'function' ) {
82- warnAboutFunction ( ) ;
97+ warnAboutFunctionChild ( ) ;
8398 children = children ( ) ;
8499 } else {
85- warnAboutElement ( ) ;
100+ warnAboutElementChild ( ) ;
86101 }
87102
88103 return Children . only ( children ) ;
0 commit comments