Hooks

useDocyrusCalendar

Calendar backed by a Docyrus data source. Detects the date, title, color, description and user fields, turns records into events, and wires create, update, delete and drag to the API.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-calendar
Required Packages(3 packages)
pnpm add @docyrus/api-client @docyrus/app-utils @tanstack/react-query

This is a port of the web hook with the same signature. It builds on useDocyrusDataGrid, which supplies saved views, the toolbar, filters, search and field metadata. Its own items query then requests only the columns the calendar needs.

calendarProviderProps is ready to spread onto the native Calendar, which supports all eight views (including year-timeline, quarter and 13weeks). It passes:

  • isRefreshing (from itemsQuery.isFetching)
  • the timeline options
  • the user filterItems
  • onEventCreate / onEventUpdate / onEventDelete / onEventDrop, each calling the Docyrus API

With enableDateRangeFilter, the query adds an overlap rule (start <= rangeEnd AND end >= rangeStart) and refetches whenever the visible range changes. The hook needs an authenticated RestApiClient and a QueryClientProvider above it.

Usage

import { useDocyrusClient } from '@docyrus/signin/react-native';

import { Calendar } from '@/components/docyrus-native/calendar';
import { useDocyrusCalendar } from '@/hooks/docyrus-native/use-docyrus-calendar';

export function EventsCalendar() {
  const client = useDocyrusClient();

  const cal = useDocyrusCalendar({
    client: client!,
    appSlug: 'base',
    dataSourceSlug: 'event',
    startDateFieldSlug: 'start_date',
    endDateFieldSlug: 'end_date',
    titleFieldSlug: 'subject',
    descriptionFieldSlug: 'description',
    enableDateRangeFilter: true,
    persistState: true
  });

  // Render a skeleton only on the very first load — passing `isLoading` on
  // every refetch would unmount the calendar and reset its view + date.
  if (!cal.hasLoadedOnce) return null;

  return (
    <>
      {cal.toolbar}
      <Calendar {...cal.calendarProviderProps} />
    </>
  );
}

API Reference

Options (UseDocyrusCalendarOptions<TData>)

Extends every useDocyrusDataGrid option except data, enableItemsQuery, showSelectColumn, enableRowMarkers and collection, which the calendar owns.

PropTypeDefaultDescription
clientRestApiClient—Authenticated Docyrus API client (required)
appSlugstring—App slug (required)
dataSourceSlugstring—Data source slug (required)
collectionDocyrusCalendarCollection<TData>—Custom list / create / update / delete adapter
startDateFieldSlugstringfirst field-date / field-dateTimeEvent start field
endDateFieldSlugstringend_date, end_time, due_date, … or the second date fieldEvent end field
titleFieldSlugstringname, title, label, subject, …Event title field
colorFieldSlugstringcolor / colourEvent color field
descriptionFieldSlugstringdescription, notes, content, …Event description field
userFieldSlugstringfirst user field, then record_ownerUser field that fills the user filter
colorMapRecord<string, TEventColor>—Maps field values to event colors
defaultEventDurationMinutesnumber60Event length when the end date is missing
getEvent(item, context) => DocyrusCalendarEvent<TData> | null—Replaces the built-in event builder. Return null to skip a record
defaultViewTCalendarView'month'Initial view
enableDateRangeFilterbooleanfalseLimits the query to the visible range. Native wires onVisibleRangeChange for you
timelineMaxLanesnumber3Lanes shown in each timeline row before +N more
defaultYearTimelineMode'continuous' | 'single''continuous'Initial pagination mode of the year timeline
defaultQuarterMode'continuous' | 'single''continuous'Initial pagination mode of the quarter view
staleTimenumber30000React Query stale time in ms
enableGroupMenubooleanfalseShows the group menu in the grid toolbar
enableRowHeightMenubooleanfalseShows the row-height menu in the grid toolbar
enableDisplayMenubooleanfalseShows the display menu in the grid toolbar
onReload() => void—Called after a toolbar reload
persistStateboolean | { storage?: 'session' | 'local'; key?: string }—Saves the grid's view parameters for each saved view

Result (UseDocyrusCalendarResult<TData>)

KeyTypeDescription
calendarProviderPropsOmit<CalendarProviderProps, 'children'>Ready to spread onto <Calendar> / <CalendarProvider>
eventsDocyrusCalendarEvent<TData>[]Transformed events
usersIUser[]Unique event users
filterItemsCalendarFilterItem[]User filter items
itemsTData[]Raw records
startDateField / endDateField / titleField / colorField / descriptionField / userFieldDataSourceField | nullResolved fields
hasDateFieldbooleanWhether a start-date field was found
requestedColumnsstringcolumns sent to the items endpoint
resolvedListParamsDocyrusDataGridListParamsFull query payload
createRecord(start, end, extra?) => Promise<void>Creates a record
updateRecord(recordId, data) => Promise<void>Updates a record
deleteRecord(recordId) => Promise<void>Deletes a record
moveRecord(recordId, newStart, newEnd) => Promise<void>Updates the start and end fields
visibleRange / setVisibleRange{ start: Date; end: Date } | null / setterThe range that drives the date-range filter
isLoading / isFetching / hasLoadedOncebooleanLoading flags
errorError | nullError from the schema or items request
reload() => voidRefetches the schema and the items
table / toolbar / views / fields / dataSource / activeViewId / setActiveViewId—Passed through from useDocyrusDataGrid

Native deltas

  • toolbar / table come from the native useDocyrusDataGrid, which stacks the toolbar for small screens.
  • With enableDateRangeFilter, calendarProviderProps.onVisibleRangeChange is already wired to setVisibleRange. On web you wire it yourself. Pass your own onVisibleRangeChange after the spread to override it. Identical ranges are ignored.
  • The items query keeps the previous result while a new range loads (keepPreviousData). Navigating shows the isRefreshing spinner over the current events instead of clearing the calendar.

Type Exports

TypeDescription
UseDocyrusCalendarOptions<TData>Hook options
UseDocyrusCalendarResult<TData>Hook result
DocyrusCalendarEvent<TData>IEvent plus recordId and item
DocyrusCalendarCollection<TData>Collection adapter
DocyrusCalendarEventBuilderContext<TData>Context passed to getEvent
IEvent, IUser, TCalendarView, TEventColor, CalendarFilterItemRe-exported calendar types

On this page