Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Broken Redux Reducer
const initialState = {
snacks: []
const logCaloriesReducer = (state, action) => {
// check for state undefined to prevent
// redux from crashing app on load
if (typeof state === 'undefined') {
return initialState;
switch(action.type) {
const updatedState = { ...state };
const indexOfNextSnack = updatedState.snacks.length;
const newSnack = {
calories: action.payload.calories,
time: action.payload.time
updatedState.snacks[indexOfNextSnack] = newSnack;
return updatedState;
return state;
return state;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.