Skip to content

Commit

Permalink
[Fix]Commit 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ChungO5 committed Jun 21, 2024
1 parent 1ca65d4 commit 325719a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
102 changes: 51 additions & 51 deletions src/pages/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,59 @@ const Main = () => {
const [page, setPage] = useState(1);
const loaderRef = useRef(null);

// useEffect(() => {
// const getData = async () => {
// try {
// const params = { page: 0, size: 5, sort: gameSort };
// const apiData = await getGameRanking(params);
// setGameList(apiData);
// setIsLoading(false);
// setPage(1);
// } catch (error) {
// console.error();
// }
// };
useEffect(() => {
const getData = async () => {
try {
const params = { page: 0, size: 5, sort: gameSort };
const apiData = await getGameRanking(params);
setGameList(apiData);
setIsLoading(false);
setPage(1);
} catch (error) {
console.error();
}
};

// getData();
// }, [gameSort]);
getData();
}, [gameSort]);

// useEffect(() => {
// const fetchMoreData = async () => {
// try {
// setTimeout(async () => {
// const newList = await getGameRanking({
// page: page,
// size: 5,
// sort: gameSort,
// });
// if (newList.length === 0) {
// return;
// }
// setGameList((prevList) => [
// ...prevList,
// { gameId: "ad" },
// ...newList,
// ]);
// setPage((prevPage) => prevPage + 1);
// }, 100);
// } catch (error) {
// console.error();
// }
// };
// const observer = new IntersectionObserver(
// (entries) => {
// const firstEntry = entries[0];
// if (firstEntry.isIntersecting) {
// fetchMoreData();
// }
// },
// { threshold: 1.0 }
// );
// if (loaderRef.current) {
// observer.observe(loaderRef.current);
// }
// return () => observer.disconnect();
// }, [loaderRef, page, gameSort]);
useEffect(() => {
const fetchMoreData = async () => {
try {
setTimeout(async () => {
const newList = await getGameRanking({
page: page,
size: 5,
sort: gameSort,
});
if (newList.length === 0) {
return;
}
setGameList((prevList) => [
...prevList,
{ gameId: "ad" },
...newList,
]);
setPage((prevPage) => prevPage + 1);
}, 100);
} catch (error) {
console.error();
}
};
const observer = new IntersectionObserver(
(entries) => {
const firstEntry = entries[0];
if (firstEntry.isIntersecting) {
fetchMoreData();
}
},
{ threshold: 1.0 }
);
if (loaderRef.current) {
observer.observe(loaderRef.current);
}
return () => observer.disconnect();
}, [loaderRef, page, gameSort]);

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/services/UserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const postUser = async (params) => {
return response.data;
})
.catch((error) => {
alert(error.response.data.message);
alert("에러가 발생했습니다.");
return error;
});
return data;
Expand Down

0 comments on commit 325719a

Please sign in to comment.