Skip to main content

Overview

useEntityList is the primary hook for building entity feeds. Each call receives a unique listId that namespaces its Redux state, so multiple independent lists can coexist on the same page. See Fetching Entities for a full guide on using this hook. Loaded lists stay current with changes the user makes through these hooks: saving an entity to a collection or removing it from one (addToCollection / removeFromCollection of useCollections or useCollectionsActions) updates its saved in every list that carries saved; reacting to an entity (useReactionToggle, useAddReaction, useRemoveReaction) updates its userReaction and reactionCounts; editing it (useUpdateEntity) updates the edited fields; posting a comment through a comment section updates its commentsCount; renaming a collection (updateCollection) updates its name in saved; and deleting a collection (deleteCollection) drops it, and every collection under it, from saved.collections, with isSaved staying true only while another collection is listed. An EntityProvider given an entity from the list follows these updates. They don’t reach an EntityProvider that fetched the entity itself, or entities held by useFetchManyEntitiesWrapper; fetch those again to see the change.

Usage Example

Props

string
required
Unique identifier for this list. Used to namespace Redux state. Must be stable across renders.
(foreignId: string) => Promise<Record<string, any> | null>
Optional. A function called for each entity with a foreignId. Its result is merged into the entity under an infusion key. See Infusing Data.

Source and space

By default the list has no source or space filter, so it shows every entity. The config object passed to fetchEntities narrows it:
string | "none" | null
Only entities from this source, or "none" for entities with no source. null or left out: no source filter (the default), so entities from any source, or none.
string | "none" | null
Only entities in this space, or "none" for entities in no space. null or left out: no space filter (the default).
A filter set to null is left out of the request; "none" is sent only when you pass it (see Saying “no value”). createEntity gives the new entity the list’s source and space; a list filtered to "none" creates it with no source or no space.

Reputation

The config object passed to fetchEntities accepts an optional spaceReputation object that opts each row’s embedded author into an added spaceReputation number. Only spaces the viewer can read count: a space they can’t read reads 0 (see Who sees space reputation).
object | null
Opt-in. Adds a spaceReputation number to each row’s embedded author. null or left out: none. Like the rest of config, it applies to this fetch and the loadMore calls after it; a later fetchEntities call without it drops it. This is a context surface, so spaceId accepts "context".

Return Values

Entity[]
The current list of loaded entities.
(Entity & { infusion: Record<string, any> })[]
Entities merged with data from infuseData. Empty array if infuseData was not provided.
boolean
true while a fetch or load-more is in progress.
SublayError | null
The last load failure, or null. Cleared when the next load starts; loadMore() retries it. Shared by every mounted hook on the same listId. A SublayError.
boolean
true while loadMore() has something to fetch: a next page, or a load that failed.
({ filters?, sort?, config?, options? }) => void
Loads the first page with the given filters, sort, and config, passed as one object: filters merge into the list’s current filters, sort and config are the list’s settings, and options control this fetch. Debounced by default (800ms). See Fetching Entities for the full parameter reference.
() => Promise<void>
Load the next page of entities and append it, or retry the load that failed (a failed first page is retried as the first page). Does nothing before the first fetchEntities, while a load is running on this list, while a debounced filter change is waiting to be fetched, or when there is nothing more. Never rejects: a failure lands in error.
() => Promise<void>
Reload page 1 with the list’s stored filters, sort and config; a debounced filter change still waiting runs now instead. The loaded entities stay until the new first page replaces them. Does nothing before the first fetchEntities. Never rejects: a failure lands in error.
(props: EntityListCreateEntityProps) => Promise<Entity | undefined>
Creates a new entity and inserts it into the list. Accepts foreignId, title, content, attachments, keywords, location and metadata, plus insertPosition: "first" | "last"; the source and space come from the list. JSON only: it takes no images or files. To create an entity with uploads, use useCreateEntity.
(props: { entityId: string }) => Promise<void>
Deletes an entity and removes it from the local list state.
"createdAt" | "hot" | "top" | "controversial" | "metadata.field" | null
Current sort algorithm.
"upvote" | "downvote" | "like" | "love" | "wow" | "sad" | "angry" | "funny" | null
Current reaction sort type. Only sent while sortBy is "top".
"asc" | "desc" | null
Current sort direction. Not sent with "hot" or "controversial", which rank one way only.
"auto" | "numeric" | "text" | "boolean" | "timestamp" | null
Current sort type hint for metadata sorts.
"day" | "week" | "month" | "year" | null
Active time frame filter.
string | "none" | null
The source filter in use (from config): a source id, "none" (entities with no source), or null when no source filter is set (every entity).
string | null
Active user ID filter.
boolean
Whether the followed-only filter is active.
KeywordsFilters | null
Active keywords filter.
TitleFilters | null
Active title filter.
ContentFilters | null
Active content filter.
AttachmentsFilters | null
Active attachments filter.
LocationFilters | null
Active location filter.
MetadataFilters | null
Active metadata filter.