0

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

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.