본문 바로가기
Tech/mobx

mobx 이슈 정리

by egas 2022. 6. 3.

1. Understanding reactivity

array.push()

https://spectrum.chat/mobx-state-tree/general/array-changes-are-not-reactive~6cf40135-3e13-4268-8a98-ba5fdabb8767

 

array에 push를 했지만 리렌더링이 되지 않는다.

const addItem = (newItem) => {
    self.myArray.push(newItem);
};

리렌더링 되지 않는 이유는 메모리에서 array의 참조값이 변하지 않았기 때문이다. observer component에서 array의 메서드나 length에 접근해보자. (JSON.stringify() 나 slice(), toJS()와 같이 복사하는 방법도 가능하다.)

https://ko.mobx.js.org/understanding-reactivity.html

 

반응성 이해하기 · MobX

<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CEBD4KQ7&placement=mobxjsorg" id="_carbonads_js"></script>

ko.mobx.js.org

 

728x90

댓글