Am I mutating the redux state in reducer?
Clash Royale CLAN TAG#URR8PPP
Am I mutating the redux state in reducer?
I am trying to change one item in of an array in my state using a reducer.
State looks like:
state:
items: [
id: 1,
name: 'Superman',
wearsCape: true
,
id: 2,
name: 'Batman',
wearsCape: true
,
id: 3,
name: 'Iron Man',
wearsCape: false
];
I am trying to filter through all the items in the state to search for first occurance of a superhero that has name equal sHero.name
. Then I am trying to change a property of found superhero. The reducer code looks like:
sHero.name
function findCapedCrusader(state, sHero )
var result = state.items.filter(s =>
return s.name === sHero.name;
);
result[0].wearsCape = false;
return ...state ;
Am I mutating the state by doing the above??
NOTE: apologies for stupid example. I am new to react and redux.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.