Skip to content

Commit

Permalink
✨Feat: queryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
shlee9999 committed Dec 5, 2024
1 parent d2d49d5 commit 819f3e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/apis/chatRoom/useSocialData.tsx
Original file line number Diff line number Diff line change
@@ -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),
},
],
Expand Down
3 changes: 2 additions & 1 deletion src/apis/member/useFetchProfile.tsx
Original file line number Diff line number Diff line change
@@ -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<FetchProfileResponse, Error> => {
return useSuspenseQuery<FetchProfileResponse, Error>({
queryKey: ['profile', memberId],
queryKey: queryKey.profile(memberId),
queryFn: () => fetchProfile({ memberId }).then(data => data.data),
staleTime: 1000 * 60 * 5, // 5분
})
Expand Down
7 changes: 7 additions & 0 deletions src/constants/queryKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const queryKey = {
social: {
chatRoomList: () => ['chatRoomList'],
friendList: () => ['friendList'],
},
profile: (memberId: number) => ['profile', memberId],
}
1 change: 1 addition & 0 deletions src/pages/ProfilePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as S from './styles'
function ProfileContent({ id }: { id: number }) {
const { data } = useFetchProfile(+id)
const navigate = useNavigate()

return (
<S.ProfilePage>
<Helmet>
Expand Down

0 comments on commit 819f3e2

Please sign in to comment.