StephenGrider / ReduxSimpleStarter

Starter pack for an awesome Udemy course
MIT License
3.56k stars 4.63k forks source link

Reducer "activeBook" returned undefined during initialization #260

Closed jack1012t closed 6 years ago

jack1012t commented 6 years ago

I am getting this error despite setting the initial state to null. See below:

reducer_active_book.js:

export default function (state = null, action) {
  switch(action.type) {
    case 'BOOK_SELECTED':
      return action.payload;
  }

  return state;
}

reducers/index.js

import { combineReducers } from 'redux';
import BooksReducer from './reducer_books';
import ActiveBook from './reducer_active_book'

// this is the mapping of the state
const rootReducer = combineReducers({
  books: BooksReducer,
  activeBook: ActiveBook
});

export default rootReducer;

console Uncaught Error: Reducer "activeBook" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.

jack1012t commented 6 years ago

Nevermind, I knew it was something really stupid once I changed the reducer_active_book.js file and got the same error. It was another file in the same directory named reducer_active_book (without extension) that I somehow saved and was getting pulled into the project rather than the .js file