Easy Array Cloning

React를 사용하다 보면 immutable 이라는 단어를 많이 보게 됩니다.

pure function으로 previous state와 action으로 next state를 생성하는 과정에서 이전 상태의 일부 값을 변경하는 것이 아니라 완전히 새로운 객체를 생성해 내게 됩니다.

ReactElement 코드를 보면 다음과 같은 구문을 볼 수 있는데, 이는 Array를 복사한 새로운 Clone array를 만들어 내는 역할을 합니다.

var shadowChildren = props.children.slice(0);

이렇게 복사된 객체가 이전과 동일한지 아래와 같이 확인해 볼 수 있다.

# Tip
You forgot to set the qrcode for Alipay. Please set it in _config.yml.
You forgot to set the qrcode for Wechat. Please set it in _config.yml.
You forgot to set the business and currency_code for Paypal. Please set it in _config.yml.
You forgot to set the url Patreon. Please set it in _config.yml.
ES6 Standard Tip
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×