function increment() { return { type: "INCREMENT" } }
function decrement() { return { type: "DECREMENT" } }
function reducer(state = {count: 0}, action) { // return new state based on the incoming action.type switch(action.type) { case "INCREMENT": return { count: state.count + 1 } case "DECREMENT": return { count: state.count - 1 } default: return state } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const redux = require("redux")
function increment() {
return {
type:"INCREMENT"
}
}
function decrement() {
return {
type:"DECREMENT"
}
}
function reducer(state = {count:0}, action) {
// return new state based on the incoming action.type