diff --git a/frontend/src/components/content-list.tsx b/frontend/src/components/content-list.tsx index 235e057..7959f90 100644 --- a/frontend/src/components/content-list.tsx +++ b/frontend/src/components/content-list.tsx @@ -20,6 +20,27 @@ export function ContentList({ fetchFn, title }: ContentListProps) { const [offset, setOffset] = React.useState(0); const [hasMore, setHasMore] = React.useState(true); + const fetchInitial = React.useCallback(async () => { + setLoading(true); + try { + const response = await fetchFn({ + limit: 10, + offset: 0, + }); + setContents(response.data); + setOffset(0); + setHasMore(response.data.length === 10); + } catch (error) { + console.error("Failed to fetch contents:", error); + } finally { + setLoading(false); + } + }, [fetchFn]); + + React.useEffect(() => { + fetchInitial(); + }, [fetchInitial]); + const loadMore = React.useCallback(async () => { if (!hasMore || loading) return; @@ -46,32 +67,12 @@ export function ContentList({ fetchFn, title }: ContentListProps) { onLoadMore: loadMore, }); - React.useEffect(() => { - const fetchInitial = async () => { - setLoading(true); - try { - const response = await fetchFn({ - limit: 10, - offset: 0, - }); - setContents(response.data); - setHasMore(response.data.length === 10); - } catch (error) { - console.error("Failed to fetch contents:", error); - } finally { - setLoading(false); - } - }; - - fetchInitial(); - }, [fetchFn]); - return (
{title &&

{title}

}
{contents.map((content) => ( - + ))}