I know I should not mutate state directly in React, but how about situation when I use function:
onSocialClick = e => {
const id = e.target.value;
this.setState((prevState, props) => {
prevState[id] = !(prevState[id]);
return prevState;
});
};
Is it a mistake to modify passed object?
EDIT:
It turns out that most of us were wrong here. React docs state it clearly now:
state is a reference to the component state at the time the change is being applied. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from state and props
Thanks to @Tomáš Hübelbauer for pointing it out in the comment.