Skip to content

Commit b4adfa1

Browse files
committed
feat: 12.CartUseReducer: context: Implement updateItem function Dispatch the action that update the amount of items in cart
1 parent 66eb3ab commit b4adfa1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/projects/12.CartUseReducer/context.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ const AppProvider = ({ children }) => {
2727
dispatch ({ type: 'REMOVE_ITEM', id })
2828
}
2929

30+
// Dispatch the action that update the amount of items in cart
31+
const updateAmount = (id, type, amount) => {
32+
dispatch ({ type: 'UPDATE_AMOUNT', payload: { id, type, amount }})
33+
}
34+
3035
return (
3136
<AppContext.Provider
3237
value={{
3338
...state,
3439
clearCart,
35-
removeItem
40+
removeItem,
41+
updateAmount
3642
}}
3743
>
3844
{children}

0 commit comments

Comments
 (0)