Skip to content

qwa1822/2023Shopping

Repository files navigation

React + Vite

사용언어는 ?

React, TypeScript

홈페이지

장바구니 추가



export const bazarSlice = createSlice({
  name: "bazar",
  initialState,
  reducers: {
    addToCart: (state, action) => {
      const item = state.productData.find(
        item => item.id === action.payload.id
      );
      if (item) {
        item.quantity++;
      } else {
        state.productData.push({ ...action.payload, quantity: 1 });
      }
    }


장바구니 삭제

    deleteItem: (state, action) => {
      state.productData = state.productData.filter(
        item => item.id !== action.payload.id
      );
    },

장바구니 초기화

resetCart: state => {
  state.productData = [];
},
incrementQuantity: (state, action) => {
  let findIdx = state.productData.find(
    item => item.id === action.payload.id
  );
  if (findIdx) {
    findIdx.quantity++;
  }
}

수량 증가

decrementQuantity: (state, action) => {
  let findIdx = state.productData.find(
    item => item.id === action.payload.id
  );
  if (findIdx.quantity == 1) {
    findIdx.quantity = 1;
  } else {
    findIdx.quantity--;
  }
},

유저추가

    addUser: (state, action) => {
      state.userInfo = action.payload;
    },
    removeUser: state => {
      state.userInfo = null;
    },
  },
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published