2017-10-21 41 views
0

我使用https://github.com/stylesuxx/generator-react-webpack-redux的发电机。发展,例外的是我在浏览器控制台减速机为空时,商店没有有效的减速机

warning.js:10 Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.

错误在index.js在减小文件罚款去,代码如下陈述:

import { combineReducers } from 'redux'; 

const reducers = {}; 
const combined = combineReducers(reducers); 
module.exports = combined; 

index.js中存储文件,代码如下所示:

import { createStore } from 'redux'; 
import reducers from '../reducers'; 

function reduxStore(initialState) { 
    const store = createStore(reducers, initialState, 
    window.devToolsExtension && window.devToolsExtension()); 

    if (module.hot) { 
    // Enable Webpack hot module replacement for reducers 
    module.hot.accept('../reducers',() => { 
     // We need to require for hot reloading to work properly. 
     const nextReducer = require('../reducers'); // eslint-disable-line global-require 

     store.replaceReducer(nextReducer); 
    }); 
    } 

    return store; 
} 

export default reduxStore; 

我没有在当前的开发中使用redux,但我使用了gener ator进行配置以供将来进行规划。任何想法如何使减速器像上面的代码const reducers = {};空没有触发任何警告?

回答

1

你需要的是一个有效的减速器,因为错误提示。 要么你可以试试下面的,如果你想保持样板或

const reducers = { somename:() => {} }; 
const combined = combineReducers(reducers); 
module.exports = combined; 

,或者尝试

module.exports =() => {}; 

这将确保返回有效的减速功能。既然你没有使用redux,这不会是一个问题。

0

为什么不尝试创建一个函数而不是空对象?

根据Redux的文件应该是一个功能:

减速机(功能):返回下一个状态树有还原能力,鉴于目前的状态树和动作来处理。 https://github.com/reactjs/redux/blob/master/docs/api/createStore.md

此外,我不知道,如果你需要使用combinereducers因为你只能有一个。