react-native – 不支持在reactnative redux中动态更改`store`

前端之家收集整理的这篇文章主要介绍了react-native – 不支持在reactnative redux中动态更改`store`前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
错误信息 –

提供商不支持即时更改商店.您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重新加载Reducer.有关迁移说明,请参阅https://github.com/reactjs/react-redux/releases/tag/v2.0.0.

configureStore.js –

  1. import { createStore,applyMiddleware } from 'redux';
  2. import ReduxThunk from 'redux-thunk';
  3. import reducers from './reducers';
  4.  
  5. export default function configureStore(initialState) {
  6. const store = createStore(reducers,{},applyMiddleware(ReduxThunk));
  7.  
  8. if (module.hot) {
  9. // console.log("in module.hot");
  10. console.log(reducers);
  11. module.hot.accept( () => {
  12. const nextRootReducer = require('./reducers/index').default;
  13. store.replaceReducer(nextRootReducer)
  14. });
  15. }
  16. return store;
  17. }

App.js –

  1. render(){
  2. const store = configureStore();
  3. return(
  4. <Provider store = {store}>
  5. <Container>
  6. <Login/>
  7. </Container>
  8. </Provider>

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

视频中给出的解决方案已实施

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

相反,尝试将configureStore()调用移动到组件外部.

  1. const store = configureStore();
  2.  
  3. class App extends React.Component {
  4.  
  5. render(){
  6.  
  7. return(
  8. <Provider store = {store}>
  9. <Container>
  10. <Login/>
  11. </Container>
  12. </Provider>

猜你在找的React相关文章