2017-09-05 31 views
4

錯誤信息 -<Provider>不支持隨時改變`store`在reactnative +終極版

供應商不支持隨時改變商店。您最有可能看到此錯誤,因爲您已更新到Redux 2.x和React Redux 2.x,它們不再自動重新加載減速器。有關遷移說明,請參閱https://github.com/reactjs/react-redux/releases/tag/v2.0.0

configureStore.js -

import { createStore,applyMiddleware } from 'redux'; 
import ReduxThunk from 'redux-thunk'; 
import reducers from './reducers'; 

export default function configureStore(initialState) { 
    const store = createStore(reducers,{},applyMiddleware(ReduxThunk)); 

    if (module.hot) { 
    // console.log("in module.hot"); 
    console.log(reducers); 
    module.hot.accept(() => { 
     const nextRootReducer = require('./reducers/index').default; 
     store.replaceReducer(nextRootReducer) 
    }); 
    } 
    return store; 
} 

App.js -

render(){ 
    const store = configureStore(); 
    return(
      <Provider store = {store}> 
       <Container> 
         <Login/> 
       </Container> 
     </Provider> 

refrence - 視頻 - https://www.youtube.com/watch?v=t2WXfAqLXJw
github上 - 在給定的視頻https://github.com/reactjs/react-redux/releases/tag/v2.0.0

方案是這樣實現

回答

4

您已經實現了在模塊熱加載時更改減速器的要求,但您仍嘗試爲每個渲染器創建新的存儲器。

請嘗試將您的configureStore()調用移動到組件外部。

const store = configureStore(); 

class App extends React.Component { 

    render(){ 

     return(
       <Provider store = {store}> 
        <Container> 
         <Login/> 
        </Container> 
       </Provider>