Skip to main content

getState

Returns a non-reactive snapshot of the calendar store state - the active date, view, visible range, events, filters, and currently selected event. Use it for one-off reads. For reactive subscriptions, use getReactiveState.

Usage

getState(): State;

type State = {
currentDate: Date;
currentView: string;
rangeLabel: string;
visibleDateRange: { start: Date; end: Date };
events: EventsStore;
viewData: any;
filters: Map<string, (obj: any) => boolean>;
editorData: CalendarEvent | null;
};

State fields:

FieldTypeDescription
currentDateDatePivot date that determines the visible range.
currentViewstringActive view id.
rangeLabelstringDisplay label for the current date range (e.g. "May 2026").
visibleDateRange{ start: Date; end: Date }Start and end of the visible range.
eventsEventsStoreInternal event storage with CRUD methods.
viewDataanyView-model-specific render data for the active view.
filtersMap<string, (obj) => boolean>Active filter predicates keyed by tag.
editorDataCalendarEvent | nullCurrently selected event, or null.

Example

import { useRef } from "react";
import { Calendar } from "@wx/react-calendar";

const apiRef = useRef(null);

const logState = () => {
const state = apiRef.current.getState();
console.log(state.currentView, state.rangeLabel);
};

<Calendar events={events} ref={apiRef} />
<button onClick={logState}>Log state</button>
  • getReactiveState — same fields, returns reactive state values.
  • getStores — direct store access for advanced integrations.
  • getEvents — list events filtered by date range.
  • exec — dispatch actions that change this state.