-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/22 메인페이지 태그리스트,페이지네이션,게시물(최종pr) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "feature/22-\uBA54\uC778\uD398\uC774\uC9C0-\uD0DC\uADF8\uB9AC\uC2A4\uD2B8,\uD398\uC774\uC9C0\uB124\uC774\uC158,\uAC8C\uC2DC\uBB3C"
Conversation
src/pages/HomePage.tsx
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 훅이나 fetch문은 외부에서 관리하면 컴포넌트가 조금 더 보기 편해질 것 같아요.
DM 드렸던대로 하나의 useQuery문 안에서 해결하는 방법을 적용해보면 더 좋을 것 같고요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네! 멘토님의 조언 덕분에 잘 해결해나가고 있습니다! 감사합니다:)
src/pages/HomePage.tsx
Outdated
| const params = new URLSearchParams(location.search); | ||
|
|
||
| const { data, isLoading, error } = useQuery({ | ||
| queryKey: ['mainData', location.search, selectedTags], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryKey는 둘 중 하나만 있어도 되지 않을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 지금 멘토님 말대로 열심히 수정해보겠습니다:)
src/pages/HomePage.tsx
Outdated
| params.append('tags', tag.toString()); | ||
| }); | ||
|
|
||
| const response = await axios.get('/api/main/tags', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗!!! 얘 api요청이 아니에요!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
멘토님 ㅠㅠㅠㅠ 이거때문에 ㅠㅠㅠㅠ 어제,, 몇시간을 허비했네요 ㅠㅠ 감사해요
#️⃣연관된 이슈
#22
📝작업 내용
메인 페이지 작업
💬리뷰 요구사항(선택)
동현님과 얘기해봐야겠지만, 검색했을때 게시글이 나오는 기능은 시간이 없어서 안될듯합니다,,! 나중에 도전해보겠습니다:)
많이 늦어서 죄송합니다..!