fix(Profile): fix hasMore check
This commit is contained in:
parent
8831ac456b
commit
bc8a783edc
@ -30,13 +30,14 @@ export function GameTable(props: Props) {
|
||||
const [page, setPage] = useState(props.data?.length ? 1 :0);
|
||||
const fetchNextPage = useRequest<GamesData[], []>(async () => {
|
||||
const newPage = page + 1;
|
||||
if (page === 0) return [];
|
||||
const resp = await fetch(`/api/user/${props.uid}/games?page=${newPage}`);
|
||||
const nextPageData: GamesData[] = await resp.json();
|
||||
setDisplayData(data => [...data, ...nextPageData])
|
||||
setPage(newPage);
|
||||
return nextPageData;
|
||||
}, { manual: true, refreshDeps: [page] });
|
||||
const hasMore = useMemo(() => page < 2 || (fetchNextPage.data?.length || 0) === 10, [page, fetchNextPage]);
|
||||
const hasMore = useMemo(() => (props.data?.length === 10 && page < 2) || (fetchNextPage.data?.length || 0) === 10, [page, fetchNextPage]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user