Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

리액트 정리

[React] 웹게임 3. 숫자야구 스프레드 연산자 [...array] 본문

리액트/웹게임

[React] 웹게임 3. 숫자야구 스프레드 연산자 [...array]

버그킴 2020. 1. 30. 14:52

mutating data. 

기존 배열 복사해놓고 새 배열 넣어주기 : 

 

리액트에서는 push로 추가하면 변한걸 감지를 못한다. 

그래서 새 어레이 생성 + 기존배열을 한번 펴주고 + 새거 추가

 

ex. 스프레드 연산자 

const array = [1];

const array2 = [...array, 2]

const array = [1];
const array2 = [...array, 2]

=> 예전 state 참조와 현재 state가 다른걸 비교

=> false면 render를 실행한다. 

 

오브젝트도

object: {...this.state.object}

 

https://ko.reactjs.org/docs/optimizing-performance.html#the-power-of-not-mutating-data

 

성능 최적화 – React

A JavaScript library for building user interfaces

ko.reactjs.org