reducer is not a function

Try create reducers ang get data from action

But get error in console: reducer is not a function.....

My reducer:

import { INCOME_LIST } from '../actionTypes'

import Immutable from 'immutable'

    const initialUserState = {
      list: []
    }

    const listReducer = function(state = initialUserState, action) {
      switch(action.type) {
      case 'INCOME_LIST':
        return Object.assign({}, state, { list: action.data });
      }
      return state;
    }

Where I have mistake?

My Action :

import axios from 'axios'
import { INCOME_LIST } from '../actionTypes'



function receiveData(json) {
    return{
        type: INCOME_LIST,
        data: json
    }
};


export function IncomeList () {

    return dispatch => {

        return (

            axios.post('http://139.196.141.166:8084/course/income/outline',{}, {
      headers: { 'X-Authenticated-Userid': '15000500000@1' }
     }).then(function (response) {

                dispatch(receiveData(response.data));

            })

            )
    }
}

How it right way create reducer for that?

Upvotes: 3

Views: 12286

Answers (4)

Edser Moreno
Edser Moreno

Reputation: 1

It worked for me, Stop node (Ctrl + C) and restart it (npm start), reload the page (F5), you will see new results.

Upvotes: 0

Tatyana Molchanova
Tatyana Molchanova

Reputation: 1603

In my case I called the function immediately

const store = createStore(rootReducer())

instead of

const store = createStore(rootReducer)

Upvotes: 0

Mohamed Gadallah
Mohamed Gadallah

Reputation: 203

  • Store - holds our state - THERE IS ONLY ONE STATE
  • Action - State can be modified using actions - SIMPLE OBJECTS
  • Dispatcher - Action needs to be sent by someone - known as dispatching an action
  • Reducer - receives the action and modifies the state to give us a new state
    • pure functions
    • only mandatory argument is the 'type'
  • Subscriber - listens for state change to update the ui

    const initialState = {
        counter: 0
    }
    
    const reducer = (state = initialState, action) => {
        switch (action.type) {
            case 'INCREASE_COUNTER':
                return { counter: state.counter + 1 }
            case 'DECREASE_COUNTER':
                return { counter: state.counter - 1 }
        }
        return state
    }
    
    const store = createStore(reducer)
    
    class App extends Component {
    
        render() {
            return (
                <Provider store={store}>
                    <CounterApp />
                </Provider>
            );
        }
    }
    

Upvotes: 0

jaybee
jaybee

Reputation: 2290

Looks like you never exported your reducer. An export default listReducer in your listReducer.js file should do the trick.

Upvotes: 6

Related Questions