Skip to main content

Overview

useCollectionEntitiesWrapper fetches the paginated list of entities saved in a collection. It supports multiple sort modes and infinite-scroll pagination via loadMore. If no collectionId is passed, it defaults to the current collection from the Redux collections state (i.e., whatever useCollections is currently navigated to).

Usage Example

Parameters

collectionId
string | null
The collection to fetch entities from. Defaults to the current collection in Redux state.
limit
number
Number of entities per page. Default: 20.
defaultSortBy
"new" | "top" | "hot" | "added"
Initial sort mode. Default: "added" (sorted by when the entity was saved).
defaultSortDir
"asc" | "desc"
Initial sort direction. Default: "desc".
include
EntityIncludeParam
Optional associations to include with each entity (e.g., "user", "space", "topcomment").

Returns

entities
Entity[]
The current list of fetched entities. Appended to on each loadMore call.
loading
boolean
true while fetching the initial page or loading more.
hasMore
boolean
true if additional pages are available.
sortBy
"new" | "top" | "hot" | "added"
Current sort mode.
sortDir
"asc" | "desc"
Current sort direction.
setSortBy
(sortBy: 'new' | 'top' | 'hot' | 'added') => void
Change the sort mode. Resets the entity list and re-fetches from page 1.
setSortDir
(sortDir: 'asc' | 'desc') => void
Change the sort direction. Resets the entity list and re-fetches from page 1.
loadMore
() => void
Load the next page of entities. Appends to the existing list.
refetch
() => void
Reset and re-fetch from page 1.

Sort Modes