Publish to my blog (weekly)
-
Where to Fetch Data: componentWillMount vs componentDidMount
-
- componentWillMount
- componentDidMount
There are two common places to fetch data:
- In practice,
componentDidMount
is the best place to put calls to fetch data, for two reasons:
-
-
Reselect로 React와 Redux 성능 향상시키기 – 불펌 오역 블로그
- 이것이 의미하는 바는 getItemsWithTotals가 처음 실행될 때는 계산된다는 것이다. 만약 다시 한번 같은 함수가 불렸는데 입력(getItems의 결과)이 변경되지 않았다면, items와 합계에 대해 캐시된 계산 결과를 리턴할 것이다. 만약 아이템이 수정되었다면( 아이템이 추가되거나, 수량이 변경되거나, getItems의 결과에 영향을 주는 어떤 일이든), 함수는 다시 실행될 것이다.
-
댓글