Skip to content

Commit

Permalink
[ chore ] useSWR mocking 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Jul 19, 2022
1 parent 48ec781 commit c352c79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion core/api/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const useGetCommunityList = () => {
const { data, error } = useSWR('/board', baseInstance.get, {
errorRetryCount: 3,
});
console.log(`데이터 ${data}`);

return {
communityList: data,
Expand Down
17 changes: 11 additions & 6 deletions pages/community/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ export default function community() {
useGetCommunityList() as GetCommunityList;

useEffect(() => {
console.log(communityList);
if (communityList) {
let data = communityList as CommunityData[];
let data = communityList.data as CommunityData[];
data = data.filter(
(_, idx) => (currentPage - 1) * 10 <= idx && idx < currentPage * 10,
);
console.log(data);
setContentList(data);
window.scrollTo({
top: 0,
behavior: 'smooth',
});
}
}, [contentList, currentPage]);
console.log(contentList);
// setIsLoading(true);
// fetch('/board')
// .then((res) => res.json())
Expand Down Expand Up @@ -70,11 +73,13 @@ export default function community() {
</StContentBlock>
<CommunityFloatingBtn />
</StMainArticle>
<PageNavigation
currentPage={currentPage}
lastPage={Math.ceil(contentList.length / limit)}
handleCurrentPage={handleCurrentPage}
/>
{!isLoading && !isError && communityList && (
<PageNavigation
currentPage={currentPage}
lastPage={Math.ceil(contentList.length / limit)}
handleCurrentPage={handleCurrentPage}
/>
)}
</>
)}
</StCommunityWrapper>
Expand Down
2 changes: 1 addition & 1 deletion types/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface PostCommentBody {
}

export interface GetCommunityList {
communityList: CommunityData[];
communityList: { data: CommunityData[] };
isLoading: boolean;
isError: string;
}

0 comments on commit c352c79

Please sign in to comment.