Skip to content

Commit

Permalink
feat: get요청 캐싱 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YoujungSon committed Mar 27, 2023
1 parent a2fac72 commit a057cad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/apis/assetInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ AxiosInstance.interceptors.response.use(
localStorage.clear();
window.location.href = '/';
}

return Promise.reject(error);
},
);
10 changes: 9 additions & 1 deletion src/components/dashboard/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ const AssetList = () => {
const [assetList, setAssetList] = useState<assetListType[]>([]);
const searchText = useRecoilValue(searchTextState);

useEffect(() => {
const token = window.localStorage.getItem('token');
if (!token) {
alert('로그인이 필요한 페이지 입니다. 로그인해주세요.');
localStorage.clear();
window.location.href = '/';
}
}, []);
const { data, status } = useQuery({
queryKey: ['getAsset'],
queryFn: async () => await getAsset(),
retry: 0, // 실패시 재호출 몇번 할지
keepPreviousData: true,
cacheTime: 10000, // 10초 동안 캐싱
onSuccess: (data) => {
data.data.asset === 'does not exist asset';
const list = data?.data?.asset?.Assets;
Expand Down

0 comments on commit a057cad

Please sign in to comment.