-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙️ Chore: Tanstack Query 업그레이드 (#96)
* ⚙ chore(#73): install Tanstack Query * 🛠 fix(#73): tanstack query 패키지 임포트 & 개발자 도구 추가 * 🛠 fix(#73): useFetchData 수정 - Tanstack Query 적용 * 🛠 fix(#73): useSignIn 수정 - Tanstack Query 적용 * 🛠 fix(#73): useFetchDashboards 수정 - Tanstack Query 적용
- Loading branch information
Showing
6 changed files
with
86 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import { useQuery } from 'react-query'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
import { getDashboardsList } from '@/services/getService'; | ||
import { setDashboards } from '@/store/reducers/dashboardsSlice'; | ||
|
||
const fetchDashboards = async () => { | ||
const response = await getDashboardsList(); | ||
|
||
if (response.status !== 200) { | ||
throw new Error('Failed to fetch dashboards'); | ||
} | ||
|
||
return response.data; | ||
}; | ||
|
||
export const useFetchDashboards = () => { | ||
const dispatch = useDispatch(); | ||
|
||
return useQuery('dashboards', () => fetchDashboards(), { | ||
onSuccess: (data) => { | ||
dispatch(setDashboards({ dashboards: data.dashboards, totalCount: data.totalCount })); | ||
const { isLoading, error, data, isFetching } = useQuery({ | ||
queryKey: ['dashboards'], // 쿼리 키는 문자열이나 배열로 지정할 수 있습니다 | ||
queryFn: async () => { | ||
try { | ||
const response = await getDashboardsList(); | ||
if (response.status !== 200) { | ||
throw new Error('Failed to fetch dashboards'); | ||
} | ||
const data = response.data; | ||
dispatch(setDashboards({ dashboards: data.dashboards, totalCount: data.totalCount })); | ||
return data; // 데이터를 반환해야 합니다 | ||
} catch (error) { | ||
// 에러 처리 | ||
throw new Error('데이터를 불러오는 중 에러 발생: ' + error); | ||
} | ||
}, | ||
}); | ||
|
||
return { isLoading, error, data, isFetching }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters