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.
question from:
https://stackoverflow.com/questions/65838490/immutable-variable-and-pure-function-updating-state 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…