spersson
spersson

Reputation: 550

React Redux Uncaught Error: Expected the reducer to be a function

I'm learning React and have encountered a problem when trying to set up React with Redux. Im getting this error on the line with createStore:

Uncaught Error: Expected the reducer to be a function

index.js

import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware, compose} from 'redux';
import movieReducer from './reducers';
import App from './App';
import dataService from './services/dataService';

let store = createStore(movieReducer, {}, applyMiddleware(dataService));

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

reducers.js

export const movieReducer = (state = {}, action) => {
    switch (action.type){
        case 'GET_MOVIE_RECEIVED':
            return action.data;
        default:
            return state;
    }
}

I have seen other questions like this, but none of them seems to solve my problem.

Upvotes: 1

Views: 3354

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67336

You need to export default if you want to import the way you are doing:

export default (state = {}, action) => {
    switch (action.type){
        case 'GET_MOVIE_RECEIVED':
            return action.data;
        default:
            return state;
    }
}

Otherwise, you can import like this:

import { movieReducer } from './reducers';

Upvotes: 3

Related Questions