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

string | null
The collection to fetch entities from. Defaults to the current collection in Redux state.
number
Number of entities per page. Default: 20.
"new" | "top" | "hot" | "added"
Initial sort mode. Default: "added" (sorted by when the entity was saved).
SortByReaction
Initial reaction type top ranks by: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny". Only sent while sortBy is "top". Default: "upvote".
"asc" | "desc"
Initial sort direction. Default: "desc".
CollectionEntityIncludeParam
Optional associations to include with each entity: "user", "space", "topComments", "files", "grants". "saved" isn’t accepted: every entity returned already has isSaved: true. On an entity whose author has blocked the user (saved before the block), topComments is [].
number
With "topComments" included: how many top comments per entity. Server default 1, maximum 5. Not sent when include doesn’t contain "topComments".
ReactionType
With "topComments" included: the reaction whose raw count ranks the top comments. Server default "upvote". Not sent when include doesn’t contain "topComments".

Returns

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

Sort Modes

The whole collection is sorted before it is paginated, so loadMore continues the same order.