Skip to main content

getReactiveState

Returns reactive refs for each state field. Subscribe to a ref to re-render when its value changes - useful inside custom toolbar items and other child components.

Usage

getReactiveState(): TState<State>;

State fields:

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

Example

import { useRef, useEffect } from "react";
import { Calendar } from "@svar-ui/react-calendar";

function App() {
const apiRef = useRef(null);

const onInit = (obj) => {
apiRef.current = obj;
const { rangeLabel } = obj.getReactiveState();
rangeLabel.subscribe(label => console.log("range:", label));
};

return <Calendar events={events} date={date} onInit={onInit} />;
}

export default App;
  • getState — non-reactive snapshot of the same fields.
  • getStores — direct access to the underlying store instance.
  • exec — dispatch actions that mutate state.
  • Navigation bar — typical consumer of reactive state inside custom toolbar items.