Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.replyke.com/llms.txt

Use this file to discover all available pages before exploring further.

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

import { useCollectionEntitiesWrapper } from "@replyke/react-js";

function SavedFeed({ collectionId }) {
  const {
    entities,
    loading,
    hasMore,
    sortBy,
    setSortBy,
    loadMore,
    refetch,
  } = useCollectionEntitiesWrapper({
    collectionId,
    defaultSortBy: "added",
    defaultSortDir: "desc",
    limit: 20,
  });

  return (
    <div>
      <select value={sortBy} onChange={(e) => setSortBy(e.target.value as any)}>
        <option value="added">Recently Added</option>
        <option value="new">Newest</option>
        <option value="top">Top Voted</option>
      </select>
      <ul>
        {entities.map((entity) => (
          <li key={entity.id}>{entity.title}</li>
        ))}
      </ul>
      {hasMore && (
        <button onClick={loadMore} disabled={loading}>
          Load more
        </button>
      )}
    </div>
  );
}

Parameters

collectionId
string | null
The collection to fetch entities from. Defaults to the current collection in Redux state.
limit
number
Number of entities per page. Default: 20.
defaultSortBy
"new" | "top" | "hot" | "added"
Initial sort mode. Default: "added" (sorted by when the entity was saved).
defaultSortDir
"asc" | "desc"
Initial sort direction. Default: "desc".
include
EntityIncludeParam
Optional associations to include with each entity (e.g., "user", "space", "topcomment").

Returns

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

Sort Modes

ValueDescription
addedSorted by when the entity was added to the collection
newSorted by entity creation date
topSorted by vote count
hotSorted by hot score (engagement-based)