Cart reducer (React)

A code exercise of about 15 minutes: read the statement, solve «Cart reducer (React)» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

Write the reducer cartReducer(state, action) for useReducer. Actions: add (sku, price: add 1 to the quantity or create the line), remove (sku: drop the line), setQty (sku, qty: if qty ≤ 0 drop the line). Never mutate the state you receive: return a new one. An unknown action returns the same state.