The predictable state container by Dan Abramov
const counter = (state = 0, action) => {
switch (action.type) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
default:
return state;
}
}
array[index] = 'something'; // Mutation!
array.slice(0, index).concat(['something else']).concat(array.slice(index + 1);
[...array.slice(0, index), 'something else', ...array.slice(index + 1)];
object.prop = 'something'; // Mutation!
_.deepCopy(object);
Object.assign({}, object, {prop: 'something'});
{...object, prop:'something'};
array.splice(index, 1); // Mutation!
array.slice(0,index).concat(array.slice(index + 1);
[...array.slice(0, index), ...array.slice(index + 1)];
array.push(itemToAdd); // Mutation!
array.concat([itemToAdd])
[...array, 0]