-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 무한스크롤 구현
- Loading branch information
Showing
12 changed files
with
218 additions
and
132 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; | ||
import { getQuestions } from "src/apis/questions"; | ||
import { questionKeys } from "src/constants/queryKeys/questionKeys"; | ||
import { Questions } from "src/models/questions"; | ||
|
||
export const useGetQuestions = () => { | ||
const { data, isLoading, error, refetch } = useQuery<Questions>( | ||
const { data, fetchNextPage, hasNextPage, isFetched } = useInfiniteQuery( | ||
questionKeys.all, | ||
() => getQuestions(1, 100) | ||
({ pageParam = 1 }) => getQuestions(pageParam, 10), | ||
{ | ||
getNextPageParam: (lastPage) => { | ||
return lastPage.data.count > lastPage.idx + 10 | ||
? lastPage.idx + 10 | ||
: undefined; | ||
} | ||
} | ||
); | ||
|
||
return { data, isLoading, error, refetch }; | ||
return { data, fetchNextPage, hasNextPage, isFetched }; | ||
}; |
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,23 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; | ||
|
||
import { Qtype } from "src/models/questions"; | ||
import { questionKeys } from "src/constants/queryKeys/questionKeys"; | ||
import { getUserQuestions } from "src/apis/questions"; | ||
|
||
const useGetUserQQuery = (id: number, qtype: Qtype) => { | ||
const { | ||
data: questions, | ||
isLoading, | ||
refetch | ||
} = useQuery<any>( | ||
const { data, fetchNextPage, hasNextPage, isFetched } = useInfiniteQuery( | ||
questionKeys.qtype(id, qtype), | ||
() => getUserQuestions(id, qtype), | ||
({ pageParam = 1 }) => getUserQuestions(id, qtype, pageParam, 10), | ||
{ | ||
onError: (error: any) => { | ||
alert(error); | ||
getNextPageParam: (lastPage) => { | ||
return lastPage.data.count > lastPage.idx + 10 | ||
? lastPage.idx + 10 | ||
: undefined; | ||
} | ||
} | ||
); | ||
|
||
return { questions, isLoading, refetch }; | ||
return { data, fetchNextPage, hasNextPage, isFetched }; | ||
}; | ||
|
||
export default useGetUserQQuery; |
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
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
Oops, something went wrong.