Combining Reducers

Combining Reducers

To make codes modularise, we can combine multiple reducers into a single root reducer and utilize it.

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

// count Reducer
export default function countReducer(count = 0, action){
    switch(action.type){
        case "CHANGE_COUNT":
            return count + action.payload
        default:
            return count
    }   
}

Last updated

Was this helpful?