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

<script lang="ts">
import { Calendar } from "@wx/svelte-calendar";
import type { CalendarInstanceApi } from "@wx/svelte-calendar";

let api = $state<CalendarInstanceApi>();

function logState() {
const state = api.getState();
console.log(state.currentView, state.rangeLabel);
}
</script>

<Calendar {events} bind:this={api} />
<button onclick={logState}>Log state</button>
  • getReactiveState — same fields as Svelte stores.
  • getStores — direct store access for advanced integrations.
  • getEvents — list events filtered by date range.
  • exec — dispatch actions that change this state.