๐ Reference
state = {
users: [
{
id: 1,
username: 'velopert'
}
]
};
// bad code
this.state.users.push({
id: 2,
username: 'mjkim'
});
// bad code
this.state.users[0].username = 'new_velopert';
// bad code
this.state.users.push({
id: 2,
username: 'mjkim'
});
this.setState({
users: this.state.users
});
// bad code
this.setState(({users}) => {
users.push({
id: 2,
username: 'mjkim'
});
return {
users
};
});