So I have a state array containing objects, I want to update a specific value of a given object, given the object index.
const initialState = {
cars:[ {name: "golf", speed: 14, price:444}, { name:"benz", speed: 15, price:6666}]
}
so this is a sample state, what I want to do is, given the index of the object(e.g the second object) I want to update the speed to 15
my Action is
const setSpeed = (index) => {
console.log(index);
dispatch({
type: SET_SPEED,
payload: {
respond: index,
},
});
};
Above is my action that dispatches a type of SET_SPEED, and the index of the object as a payload.
I'm trying to write a reducer that update the speed by one given the index of the object