scrimba
React Bootcamp Course
Plain JS Redux - combineReducers Part 2
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Plain JS Redux - combineReducers Part 2
AboutCommentsNotes
Plain JS Redux - combineReducers Part 2
Expand for more info
redux
favoriteThings.js
run
preview
console
function addFavoriteThing(thing) {
return {
type: "ADD_FAVORITE_THING",
payload: thing
}
}

function removeFavoriteThing(thing) {
return {
type: "REMOVE_FAVORITE_THING",
payload: thing
}
}

function favoriteThingsReducer(favoriteThings = [], action) {
switch(action.type) {
case "ADD_FAVORITE_THING":
return [...favoriteThings, action.payload]
case "REMOVE_FAVORITE_THING": {
const updatedArr = favoriteThings.filter(thing => thing.toLowerCase() !== action.payload.toLowerCase())
return updatedArr
}
default:
return favoriteThings
}
}
Console
{count:
0
, favoriteThings:
[]
, youTubeVideo:
{title:
""
, viewCount:
0
, votes:
{up:
0
, down:
0
}
}
}
,
/index.html
-10:01