Advertisement
xcage88

slice

May 21st, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { createSlice } from "@reduxjs/toolkit";
  2. import { fetchAll, fetchProduct } from "../action";
  3.  
  4. export const bootcampSlice = createSlice({
  5.     name: "bootcamp",
  6.     initialState: {
  7.         loading: false,
  8.         data: [],        
  9.         entity: {
  10.             mainTitle: '',
  11.             subTitle: '',
  12.             batch: '',
  13.             mentor: {
  14.                 mentor1: '',
  15.                 mentor2: '',
  16.             },
  17.             price: '',
  18.         },
  19.         error: null,
  20.     },
  21.     extraReducers: (builder) =>
  22.         builder.addCase(fetchAll.pending, (state) => {
  23.             state.loading = true;
  24.         })
  25.         .addCase(fetchAll.fulfilled, (state, action) => {
  26.             state.data = action.payload
  27.             state.loading = false
  28.         })
  29.         .addCase(fetchAll.rejected, (state, action) => {
  30.             state.loading = true
  31.             state.error = action.payload
  32.         })
  33.        
  34.         .addCase(fetchProduct.pending, (state) => {
  35.             state.loading = true;
  36.         })
  37.         .addCase(fetchProduct.fulfilled, (state, action) => {
  38.             state.entity = action.payload
  39.             state.loading = false
  40.         })
  41.         .addCase(fetchProduct.rejected, (state, action) => {
  42.             state.loading = true
  43.             state.error = action.payload
  44.         })
  45. })
  46.  
  47. export default bootcampSlice.reducer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement