<Provider>不支持在reactnative + redux中动态更改`store`

ket*_*rni 11 react-native redux

错误信息 -

提供商不支持即时更改商店.您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重新加载Reducer.有关迁移说明,请参阅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;
}
Run Code Online (Sandbox Code Playgroud)

App.js -

render(){
    const store = configureStore();
    return(
          <Provider store = {store}>
                <Container>
                      <Login/>
                </Container>
        </Provider>
Run Code Online (Sandbox Code Playgroud)

参考 - 视频 - https://www.youtube.com/watch?v=t2WXfAqLXJw
github - https://github.com/reactjs/react-redux/releases/tag/v2.0.0

实现了视频中给出的解决方案

Ric*_*lay 12

您已经实现了在模块加载热量时更改reducer的要求,但您仍在尝试为每个渲染创建一个新的存储.

相反,尝试将您的configureStore()呼叫转移到组件外部.

const store = configureStore();

class App extends React.Component {

    render(){

        return(
              <Provider store = {store}>
                  <Container>
                      <Login/>
                  </Container>
              </Provider>
Run Code Online (Sandbox Code Playgroud)