ReduxSimpleStarter icon indicating copy to clipboard operation
ReduxSimpleStarter copied to clipboard

Books Reducers Initial State Undefined

Open aali87 opened this issue 8 years ago • 5 comments

I just finished lecture 42. That's about implementing the container class. I'm getting an issue with passing the initial state where my books reducer is being passed an undefined state. From what I can understand, we're passing in a hard coded books object as the state. Can somebody help? I've been stuck on this for about two days now.

capture

aali87 avatar Apr 05 '17 18:04 aali87

Did you ever get this to work?

roz0n avatar Apr 13 '17 20:04 roz0n

Yeah - Turned out it was a type and it was fixed when I started over again. Are you getting the same issue?

aali87 avatar Apr 15 '17 03:04 aali87

Hi ! I get this error image

I got it after 43 lesson. Can you help me , please

MarinaCode avatar Jul 10 '17 16:07 MarinaCode

Make sure the first argument you pass on Line 1 of reducer_active_book.js contains state = null.

Like so:

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

  return state;
}

1andee avatar Aug 28 '17 02:08 1andee

I am doing exactly as @1andee says, yet I still get this error:

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

  return state;
}

bundle.js:21410 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 avatar Jul 30 '18 13:07 jack1012t