-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductreducer.js
32 lines (28 loc) · 915 Bytes
/
Productreducer.js
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
30
31
32
import { createSlice } from "@reduxjs/toolkit";
import { incrementQuantity } from "./Cartreducer";
const initialState ={
product:[],
}
export const productSlice = createSlice({
name:'product',
initialState,
reducers:{
getProducts:(state,action)=>{
state.product.push(action.payload)
},
incrementQty:(state,action)=>{
const itemPresent = state.product.find(
(item) => item.id === action.payload.id
);
itemPresent.quantity++;
},
decrementQty:(state,action)=>{
const itemPresent = state.product.find(
(item) => item.id === action.payload.id
);
itemPresent.quantity--;
}
}
})
export const {getProducts,incrementQty,decrementQty} =productSlice.actions;
export default productSlice.reducer;