<Provider> does not support changing `store`_企业IT_编程问答

<Provider> does not support changing `store`

来源:互联网  时间:2018/1/27 2:16:24

关于网友提出的“ <Provider> does not support changing `store`”问题疑问,本网通过在网上对“ <Provider> does not support changing `store`”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: <Provider> does not support changing `store`
描述:

Redux 热更新 不可用


// index.js

import React from 'react'
import { Provider } from 'react-redux'
import { render } from 'react-dom'

import configureStore from './configureStore'
import App from './app'

import './index.less'

const rootEl = document.getElementById('app')

const store = configureStore()

render(
  <Provider store={store}>
    <App />
  </Provider>,
  rootEl,
)

// configureStore.js

export default function configureStore(initialState) {
  const middleware = []
  const store = createStore(
    rootReducer,
    initialState,
    compose(
      applyMiddleware(...middleware),
      process.env.NODE_ENV !== 'production' &&
      window.__REDUX_DEVTOOLS_EXTENSION__ &&
      window.__REDUX_DEVTOOLS_EXTENSION__(),
    ),
  )

  if (module.hot) {
    module.hot.accept('./reducers', () => {
      const nextRootReducer = require('./reducers/index').default
      store.replaceReducer(nextRootReducer)
    })
  } else {
    console.log('not hot')
  }

  return store
}

目录结构


解决方案1:

store被修改了?
给运行正常的代码:
store.js

import {createStore, applyMiddleware, compose} from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import YourReducer from '../reducers/YourReducer.js'; //import your reducer
let createStoreWithMiddleware = null;

if(process.env.NODE_ENV === 'production') {
    createStoreWithMiddleware = compose(applyMiddleware(
        thunkMiddleware
    ))(createStore);
} else {
    createStoreWithMiddleware = compose(applyMiddleware(
        thunkMiddleware,
        createLogger()
    ), window.devToolsExtension ? window.devToolsExtension() : f => f)(createStore);
}

export default (initState) => {
    return createStoreWithMiddleware(YourReducer, initState);
}

index.js

import {Provider} from 'react-redux';
import store from './stores/store.js';
<Provider store={store()}>
//...
</Provider>

上一篇html5(公众号)怎么做到微信浏览器强制竖屏
下一篇ezsql和memcache哪个sql缓存效率高?
明星图片
相关文章
《 <Provider> does not support changing `store`》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)