From 819f3e2045ffa06b6f08b0ed96e3df73dcefad5e Mon Sep 17 00:00:00 2001 From: shlee9999 <95556588+shlee9999@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:41:07 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Feat:=20queryKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/chatRoom/useSocialData.tsx | 5 +++-- src/apis/member/useFetchProfile.tsx | 3 ++- src/constants/queryKey.ts | 7 +++++++ src/pages/ProfilePage/index.tsx | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/constants/queryKey.ts diff --git a/src/apis/chatRoom/useSocialData.tsx b/src/apis/chatRoom/useSocialData.tsx index 5282461..3d45bab 100644 --- a/src/apis/chatRoom/useSocialData.tsx +++ b/src/apis/chatRoom/useSocialData.tsx @@ -1,16 +1,17 @@ import { useSuspenseQueries } from '@tanstack/react-query' import { fetchChatRoomList } from '~apis/chatRoom/fetchChatRoomList' import { fetchFriendList } from '~apis/friend/fetchFriendList' +import { queryKey } from '~constants/queryKey' export function useSocialData() { const results = useSuspenseQueries({ queries: [ { - queryKey: ['chatRoomList'], + queryKey: queryKey.social.chatRoomList(), queryFn: () => fetchChatRoomList().then(res => res.data), }, { - queryKey: ['friendList'], + queryKey: queryKey.social.friendList(), queryFn: () => fetchFriendList().then(res => res.data), }, ], diff --git a/src/apis/member/useFetchProfile.tsx b/src/apis/member/useFetchProfile.tsx index 5796498..9d7a80e 100644 --- a/src/apis/member/useFetchProfile.tsx +++ b/src/apis/member/useFetchProfile.tsx @@ -1,9 +1,10 @@ import { useSuspenseQuery, UseSuspenseQueryResult } from '@tanstack/react-query' import { fetchProfile, FetchProfileResponse } from '~apis/member/fetchProfile' +import { queryKey } from '~constants/queryKey' export const useFetchProfile = (memberId: number): UseSuspenseQueryResult => { return useSuspenseQuery({ - queryKey: ['profile', memberId], + queryKey: queryKey.profile(memberId), queryFn: () => fetchProfile({ memberId }).then(data => data.data), staleTime: 1000 * 60 * 5, // 5분 }) diff --git a/src/constants/queryKey.ts b/src/constants/queryKey.ts new file mode 100644 index 0000000..3a216be --- /dev/null +++ b/src/constants/queryKey.ts @@ -0,0 +1,7 @@ +export const queryKey = { + social: { + chatRoomList: () => ['chatRoomList'], + friendList: () => ['friendList'], + }, + profile: (memberId: number) => ['profile', memberId], +} diff --git a/src/pages/ProfilePage/index.tsx b/src/pages/ProfilePage/index.tsx index 7ab7656..c23d87a 100644 --- a/src/pages/ProfilePage/index.tsx +++ b/src/pages/ProfilePage/index.tsx @@ -16,6 +16,7 @@ import * as S from './styles' function ProfileContent({ id }: { id: number }) { const { data } = useFetchProfile(+id) const navigate = useNavigate() + return (