I am creating a useReducer that, e.g., sets the price of an item.
const reducer = (state, action) => {
switch (action.type) {
case 'SET_PRICE':
return {
...state,
price: action.payload,
}
default:
return state
}
}
I now have to have multiple of these SET_PRICE, as I have hundreds of products, so I started writing
case 'SET_PRICE_0':
return {
...state,
price_0: action.payload,
}
case 'SET_PRICE_1':
return {
...state,
price_1: action.payload,
}
...
I can see that there's something wrong if I write over 10 of these, let alone 100... Is there an alternative to write less code?