Feature/22 메인페이지 태그리스트,페이지네이션,게시물(최종pr)#37
Open
Conversation
hwookim
reviewed
Dec 20, 2024
src/pages/HomePage.tsx
Outdated
Comment on lines
11
to
45
| const fetchPostsByTags = async (selectedTags: number[]) => { | ||
| const params = new URLSearchParams(); | ||
| selectedTags.forEach((tag) => { | ||
| params.append('tags', tag.toString()); | ||
| }); | ||
|
|
||
| const response = await axios.get('/api/main/tags', { | ||
| params | ||
| }); | ||
| console.log('tagsposts', response.data); // html 형식으로 날아옴 | ||
| return response.data; | ||
| }; | ||
|
|
||
| const useMainData = (selectedTags: number[]) => { | ||
| const location = useLocation(); | ||
| const params = new URLSearchParams(location.search); | ||
|
|
||
| const { data, isLoading, error } = useQuery({ | ||
| queryKey: ['mainData', location.search, selectedTags], | ||
| queryFn: () => | ||
| fetchMainData({ | ||
| currentPage: params.get('page') ? Number(params.get('page')) : 1, | ||
| limit: 20, | ||
| }), | ||
| enabled: selectedTags.length === 0 | ||
| }); | ||
|
|
||
| return { | ||
| posts: data?.posts, | ||
| tags: data?.tags, | ||
| pagination: data?.pagination, | ||
| isLoading, | ||
| error, | ||
| }; | ||
| }; |
There was a problem hiding this comment.
이런 훅이나 fetch문은 외부에서 관리하면 컴포넌트가 조금 더 보기 편해질 것 같아요.
DM 드렸던대로 하나의 useQuery문 안에서 해결하는 방법을 적용해보면 더 좋을 것 같고요!
Contributor
Author
There was a problem hiding this comment.
네! 멘토님의 조언 덕분에 잘 해결해나가고 있습니다! 감사합니다:)
src/pages/HomePage.tsx
Outdated
| const params = new URLSearchParams(location.search); | ||
|
|
||
| const { data, isLoading, error } = useQuery({ | ||
| queryKey: ['mainData', location.search, selectedTags], |
Contributor
Author
There was a problem hiding this comment.
넵! 지금 멘토님 말대로 열심히 수정해보겠습니다:)
src/pages/HomePage.tsx
Outdated
| params.append('tags', tag.toString()); | ||
| }); | ||
|
|
||
| const response = await axios.get('/api/main/tags', { |
Contributor
Author
There was a problem hiding this comment.
멘토님 ㅠㅠㅠㅠ 이거때문에 ㅠㅠㅠㅠ 어제,, 몇시간을 허비했네요 ㅠㅠ 감사해요
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#️⃣연관된 이슈
#22
📝작업 내용
메인 페이지 작업
💬리뷰 요구사항(선택)
동현님과 얘기해봐야겠지만, 검색했을때 게시글이 나오는 기능은 시간이 없어서 안될듯합니다,,! 나중에 도전해보겠습니다:)
많이 늦어서 죄송합니다..!