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
The collection to fetch entities from. Defaults to the current collection in Redux state.
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.Initial sort mode. Default:
"addedAt" (sorted by when the entity was saved).Initial reaction type
top ranks by: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny". Only sent while sortBy is "top". Default: "upvote".Initial sort direction. Default:
"desc"; ignored (not sent) for "hot", which ranks one way only.Optional associations to include with each entity:
"user", "space", "topComments", "files", "grants". "saved" isn’t accepted: every entity returned is in this collection.With
"topComments" included: how many top comments per entity. Server default 1, maximum 5. Not sent when include doesn’t contain "topComments".With
"topComments" included: the reaction whose raw count ranks the top comments. Server default "upvote". Not sent when include doesn’t contain "topComments".Returns
The last load failure, or
null. Cleared when the next load starts; loadMore() retries it. A SublayError.Change the sort mode. Resets the entity list and re-fetches from page 1.
Change which reaction
top ranks by. Resets the entity list and re-fetches from page 1.Change the sort direction. Resets the entity list and re-fetches from page 1.
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.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.
