Skip to main content

Overview

useFetchManyEventsWrapper wraps useFetchManyEvents into a ready-to-render list: it holds the accumulated events, tracks loading/hasMore, manages sort state, and exposes loadMore and refresh. It mirrors useFetchManyEntitiesWrapper. Visibility is enforced server-side, so the list only contains events the current user may see. Changing any filter prop (or calling refresh) resets the list to page 1.

Usage Example

import { useFetchManyEventsWrapper } from "@sublay/react-js";

function EventsList() {
  const { events, loading, hasMore, loadMore, sortBy, setSortBy, refresh } =
    useFetchManyEventsWrapper({
      timeWindow: "upcoming",
      limit: 20,
      include: "userRsvp",
    });

  return (
    <>
      <button onClick={() => setSortBy("going")}>Sort by popularity</button>
      {events.map((e) => (
        <article key={e.id}>
          <h3>{e.title}</h3>
          <span>{e.rsvpCounts.going} going</span>
        </article>
      ))}
      {hasMore && <button disabled={loading} onClick={loadMore}>Load more</button>}
    </>
  );
}

Parameters

limit
number
Page size. Defaults to 10.
spaceId
string | null
Restrict to one space.
hostId
string | null
Only events this user hosts.
type
"online" | "physical" | "hybrid" | null
Filter by type.
status
"active" | "cancelled" | null
Filter by status.
timeWindow
"upcoming" | "ongoing" | "past" | null
Derived time window.
startsAfter
string | null
ISO datetime lower bound.
startsBefore
string | null
ISO datetime upper bound.
myRsvp
RsvpStatus | RsvpStatus[] | null
Statuses the logged-in user RSVP’d with.
locationFilters
object | null
Proximity filter.
titleFilters
object | null
Free-text filter on title.
descriptionFilters
object | null
Free-text filter on description.
include
string | string[]
Associations to expand.
defaultSortBy
"startTime" | "going"
Initial sort field. Defaults to "startTime".
defaultSortDir
"asc" | "desc"
Initial sort direction. Defaults to "asc".

Returns

events
Event[]
The accumulated events.
loading
boolean
true while fetching.
hasMore
boolean
Whether more pages remain.
sortBy
"startTime" | "going"
Current sort field.
sortDir
"asc" | "desc"
Current sort direction.
setSortBy
(s) => void
Change the sort field (resets to page 1).
setSortDir
(d) => void
Change the sort direction (resets to page 1).
loadMore
() => void
Advance to the next page.
refresh
() => void
Re-run the query from page 1.

See Also