프로그래밍(Programming)/리액트(React)
[리액트(React) Study Log] [Person App-020] Updating State Immutably
SuperKid
2019. 1. 11. 14:44
[리액트(React) Study Log] [Person App-020] Updating State Immutably
- state(object) 의 immutablilty 를 유지하면서 다루는 방법 : state 자체가 아니라 state 를 copy 해서 사용
- object 를 copyt 하는 방법 slice 또는 spread operator(전개연산자: ...) 를 사용.
// DO NOT USE : const persons = this.state.persons;
// const persons = this.state.persons.slice();
const persons = [...this.state.persons];