useEntityList
Hook
The useEntityList
hook provides access to all the context and functionality exposed by the EntityListProvider
. It allows developers to interact with the entity list’s data, manage its state, and dynamically modify filters. Below is the interface for all available values and functions:
export interface useEntityListDataValues {
entities: Entity[];
infusedEntities: (Entity & Record<string, any>)[];
loading: boolean;
hasMore: boolean;
resetting: boolean;
sortBy: EntityListSortByOptions | null;
setSortBy: (sortBy: EntityListSortByOptions) => void;
timeFrame: TimeFrame | null;
setTimeFrame: (timeFrame: TimeFrame | null) => void;
sourceId: string | null;
setSourceId: (sourceId: string | null) => void;
userId: string | null;
setUserId: (userId: string | null) => void;
followedOnly: boolean;
setFollowedOnly: (state: boolean) => void;
keywordsFilters: KeywordsFilters | null;
updateKeywordsFilters: (
type: "add" | "remove" | "reset",
key: "includes" | "doesNotInclude" | "both",
value?: string | string[]
) => void;
metadataFilters: MetadataFilters | null;
setMetadataFilters: (metadata: MetadataFilters | null) => void;
titleFilters: TitleFilters | null;
setTitleFilters: (metadata: TitleFilters | null) => void;
contentFilters: ContentFilters | null;
setContentFilters: (metadata: ContentFilters | null) => void;
attachmentsFilters: AttachmentsFilters | null;
setAttachmentsFilters: (metadata: AttachmentsFilters | null) => void;
locationFilters: LocationFilters | null;
setLocationFilters: (location: LocationFilters | null) => void;
kickstart: () => void;
loadMore: () => void;
resetEntities: () => Promise<void>;
createEntity: (props: {
foreignId?: string;
sourceId?: string;
title?: string;
content?: string;
attachments?: Record<string, any>[];
keywords?: string[];
location?: {
latitude: number;
longitude: number;
};
metadata?: Record<string, any>;
insertPosition?: "first" | "last";
}) => Promise<void>;
deleteEntity: (props: { entityId: string }) => Promise<void>;
}
Explanation of Hook Values and Functions
Entities and Data Management
entities
: Contains an array of all entities fetched for the list.infusedEntities
: If aninfuseData
function is provided to the provider, this array contains entities with additional external data merged. Theentities
array remains “pure,” holding only the data fetched by Replyke.loading
: A boolean flag indicating whether entities are currently being fetched. Useful for showing loading indicators in the UI.hasMore
: Indicates whether there are more entities to fetch. Iffalse
, the entity list has reached its end and there is no more data to be fetched.resetting
: A flag indicating that the entity list is currently being reset. Whenresetting
is true,loading
will also be true, but not vice versa.
Sorting
sortBy
: Holds the current sorting criteria for the entity list.setSortBy
: Updates the sorting criteria dynamically.
Filter States and Functions
The following values represent the current state of entity list filters, and corresponding functions allow dynamic updates. Each filter change will reset the entity list.
timeFrame
: The current state of the time frame filter.setTimeFrame
: Updates the time frame filter.sourceId
: The current source ID filter.setSourceId
: Updates the source ID filter.userId
: The current user ID filter.setUserId
: Updates the user ID filter.followedOnly
: A boolean indicating whether the entity lit is limited to entities from followed accounts.setFollowedOnly
: Updates thefollowedOnly
filter.keywordsFilters
: The current keywords filter state.updateKeywordsFilters
: Dynamically updates keywords filters by adding, removing, or resetting values.titleFilters
: The current state of title filters.setTitleFilters
: Updates the title filters.contentFilters
: The current state of content filters.setContentFilters
: Updates the content filters.attachmentsFilters
: The current state of attachments filters.setAttachmentsFilters
: Updates the attachments filters.locationFilters
: The current state of location filters.setLocationFilters
: Updates the location filters.metadataFilters
: The current state of metadata filters.setMetadataFilters
: Updates the metadata filters.
Actions and Mutations
kickstart
: A function that triggers the first fetch of entities manually when the idle property in the EntityListProvider is set to true.loadMore
: Fetches additional entities for the list.resetEntities
: Resets the list, refreshing data without altering filter states.createEntity
: Creates a new entity within the list’s context. The newly created entity is automatically added to the list.deleteEntity
: Deletes an entity within the lists context. The deleted entity is automatically removed from the list.
This hook gives you complete control over managing and customizing the list’s behavior, enabling a wide range of use cases. In the following chapters, we’ll explore practical examples of implementing the EntityListProvider
with useEntityList
using filters in our app.