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: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 collection/invalid-query, never lowered to 100.
"createdAt" | "addedAt" | "top" | "hot"
Initial sort mode. Default: "addedAt" (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"; ignored (not sent) for "hot", which ranks one way only.
CollectionEntityIncludeParam
Optional associations to include with each entity: "user", "space", "topComments", "files", "grants". "saved" isn’t accepted: every entity returned is in this collection.
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.
SublayError | null
The last load failure, or null. Cleared when the next load starts; loadMore() retries it. A SublayError.
boolean
true while loadMore() has something to fetch: a next page, or a load that failed.
"createdAt" | "addedAt" | "top" | "hot"
Current sort mode.
SortByReaction
Current reaction type top ranks by.
"asc" | "desc"
Current sort direction.
(sortBy: 'createdAt' | 'addedAt' | 'top' | 'hot') => 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.
() => Promise<void>
Load the next page of entities and append it, or retry the load that failed. Does nothing while a load is running or when there is nothing more. Never rejects: a failure lands in error.
The entities are kept in the shared store under the collection, so saving or removing an entity shows in every hook on that collection, but each hook pages and sorts on its own. Show a collection’s entities with one useCollectionEntitiesWrapper at a time: a second one on the same collection replaces them with its own first page.
() => Promise<void>
Reload from the first page with the current sort. The loaded entities stay until the new first page replaces them. Never rejects: a failure lands in error.

Sort Modes

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