未捕获的TypeError:(0,_reactRedux.combineReducers)不是函数

时间:2017-07-19 06:32:36

标签: reactjs react-redux

我开始反应是在试验一些东西。但我不断得到"Uncaught TypeError: (0 , _reactRedux.combineReducers) is not a function"这是我的演示配置文件

import React from 'react'
import { render } from 'react-dom'
import { createStore, applyMiddleware,compose } from 'redux'
import { Provider } from 'react-redux'

import createLogger from 'redux-logger'
import thunk from 'redux-thunk'

import App from './containers/App'
import promise from "redux-promise-middleware"
import logger from "redux-logger"

import reducer from "./reducers"

const middleware = applyMiddleware(promise(), thunk, logger())
const store= createStore(reducer,middleware)
render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
)

这个减速器的index.js     从&#34; react-redux&#34;导入{combineReducers}     从&#34; ./ UserReducer&#34;

导入用户
export default combineReducers({
    users,

    }
)

用户reducer.js

export default function reducer(state={users:[]},action){
   // console.log("inside reducer")
   switch(action.type){
       case "FETCH_USERS":{
           console.log("inside reducer",{...state})
           return {...state,users:action.payload}
       }
   } 
}

2 个答案:

答案 0 :(得分:12)

combineReducers由&#39; redux&#39;提供。包裹,而不是&#39; react-redux&#39;。

所以:     import { combineReducers } from 'redux' 应该解决它

答案 1 :(得分:1)

如何更改此

export default combineReducers({
   users,

   }
)

到此

import { combineReducers } from 'redux'
import users from './users'

const someApp = combineReducers({
  users
})

export default someApp

然后将其导入到您放置路线的app.jsindex.js。就像这样。

import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import someApp from './reducers'
import App from './components/App'

let store = createStore(someApp)

render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
)