Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: (0 , _reactRedux.combineReducers) is not a function

I have started with react was experimenting something. but I am continuously getting error sating that "Uncaught TypeError: (0 , _reactRedux.combineReducers) is not a function" here is my demo configuration file

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')
)

this index.js of reducers import { combineReducers } from "react-redux" import users from "./UserReducer"

export default combineReducers({
    users,

    }
)

User 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}
       }
   } 
}
like image 393
Sanidhya Avatar asked Jul 19 '17 06:07

Sanidhya


Video Answer


2 Answers

combineReducers is provided by the 'redux' package, not 'react-redux'.

So: import { combineReducers } from 'redux' should fix it

like image 189
Grandas Avatar answered Oct 20 '22 14:10

Grandas


How about change this

export default combineReducers({
   users,

   }
)

To this

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

const someApp = combineReducers({
  users
})

export default someApp

And import it in app.js or index.js where you put your route. Just like this.

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')
)
like image 30
Hana Alaydrus Avatar answered Oct 20 '22 15:10

Hana Alaydrus