NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 57

Reducer and rootReducer in react js

Main use of this folder :- service/reducers

Index.js :-  also known as rootReducer

Here's is the Code !!

// Reducer.js
import { ADD_TO_CART } from "../constants"
const initialState = {
    cardData: []
}
export default function cardItems(state = [], action) {
    switch (action.type) {
        case ADD_TO_CART:
            // console.warn("reducer",action)
            return [
                ...state,
                {cardData: action.data}
            ]
        default:
            return state
    }
}

// Index.js

import {combineReducers} from "redux"
import cardItems from "./reducer"

export default combineReducers({
    cardItems,
})

Chapter 56

Action in redux

Previous chapter

Chapter 58

Container - mapDispatchToProps - mapStateToProps

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex