I'm learning about immutability and pure functions. As a newbie, I'm struggling and I don't understand if the following code mutates or not the state or data.
This is the code
let state = [];
const updateState = (state, data) => {
return [...state, data];
}
state = updateState(state, 1);
console.log(state);
I want to use a pure function that receives a state and data and updates the original state.
This line state = updateState(state, 1);
feels like a mutation for me, but I'm not sure. Am I mutating the state?
Thanks for your help. I'm trying to learn.