[react-query] 캐시 데이터를 읽는 방법(queryClient vs useQuery) 캐시된 쿼리를 가져올때 onSuccess가 호출되지 않는 문제

seo·2022년 3월 23일
0

please note that accessing the cache imperatively via the queryClient does NOT create a subscription, so your component will not be re-rendered if you use this during the render function, and it will also not trigger a fetch if the cache is empty. Only useQuery does that, so I'd recommend to always useQuery to read data from the cache. –
TkDodo
Jul 11, 2021 at 13:12

queryClient를 통해 캐시에 액세스하는 것은 구독을 생성하지 않으므로 렌더링 기능 중에 이 기능을 사용해도 컴포넌트가 다시 렌더링되지 않으며 캐시가 비어 있어도 가져오기가 트리거되지 않습니다. 이 기능은 useQuery에만 적용되므로 캐시에서 데이터를 읽을 때는 항상 Query를 사용하는 것이 좋습니다.

ref.
https://stackoverflow.com/questions/67091583/react-query-how-can-i-access-my-queries-in-multiple-components

캐시된 쿼리를 가져올때 onSuccess가 호출되지 않는 문제
onSuccess doesn't get called when query is retrieved from cache
https://github.com/tannerlinsley/react-query/discussions/937

0개의 댓글