MCPcopy
hub / github.com/reduxjs/redux / reducer

Function reducer

test/typescript/reducers.ts:19–35  ·  test/typescript/reducers.ts::reducer
(state = 0, action)

Source from the content-addressed store, hash-verified

17 type State = number
18
19 const reducer: Reducer<State> = (state = 0, action) => {
20 if (action.type === class="st">'INCREMENT') {
21 const { count = 1 } = action
22 if (typeof count === class="st">'number') {
23 return state + count
24 }
25 }
26
27 if (action.type === class="st">'DECREMENT') {
28 const { count = 1 } = action
29 if (typeof count === class="st">'number') {
30 return state + count
31 }
32 }
33
34 return state
35 }
36
37 class="cm">// Reducer function accepts any object with `type` prop as action.
38 class="cm">// Any extra props are allowed too.

Callers 2

simpleFunction · 0.70
typeGuardsFunction · 0.70

Calls 1

isActionFunction · 0.70

Tested by

no test coverage detected