scrimba
React Bootcamp Course
Plain JS Redux - Handling more complex state
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

To see this lesson you need to be logged in. Joining Scrimba is free and gives you access to 20+ courses.Sign up
Plain JS Redux - Handling more complex state
AboutCommentsNotes
Plain JS Redux - Handling more complex state
Expand for more info
index.js
run
preview
console
const redux = require("redux")

function changeCount(amount = 1) {
return {
type: "CHANGE_COUNT",
payload: amount
}
}

function reducer(state = {count: 0}, action) {
switch(action.type) {
case "CHANGE_COUNT":
return {
count: state.count + action.payload
}
default:
return state
}
}

const store = redux.createStore(reducer)
store.subscribe(() => {
console.log(store.getState())
})

Console
{count:
1
}
,
/index.html
-7:04