react-native – 不支持在reactnative redux中动态更改`store`
发布时间:2020-12-15 20:46:15 所属栏目:百科 来源:网络整理
导读:错误信息 – 提供商不支持即时更改商店.您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重新加载Reducer.有关迁移说明,请参阅https://github.com/reactjs/react-redux/releases/tag/v2.0.0. configureStore.js – import { c
错误信息 –
提供商不支持即时更改商店.您很可能会看到此错误,因为您已更新到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; } App.js – render(){ const store = configureStore(); return( <Provider store = {store}> <Container> <Login/> </Container> </Provider> 参考 – 视频中给出的解决方案已实施
您已经实现了在模块加载热量时更改reducer的要求,但您仍在尝试为每个渲染创建一个新的存储.
相反,尝试将configureStore()调用移动到组件外部. const store = configureStore(); class App extends React.Component { render(){ return( <Provider store = {store}> <Container> <Login/> </Container> </Provider> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |