I'm currently importing this library:
import update from 'react-addons-update';
Here is my list:
[{id: 1, title: "some title"}, {id: 2, title: "some other title"}]
And my action:
action.type: 'change_title'
action.payload: [2, "some new title"]
The first parameter in action.payload refers to the id of the array I would like to change
Here is my reducer code:
export default (state = [], action) => {
switch (action.type) {
case 'change_title':
return update(state, {
0: {
title: { $set: action.payload[1] }
}
});
default:
return state;
}
};
As you can see, in it's current state my reducer function always changes the "title" value in the first array, but I would like to know: How can I specify which array to modify based on the "id" value?