API reference
State store
Create calendar state outside Root, and change it from anywhere in your app.
Root creates a store for its state automatically. Create one yourself when
code outside Root needs to change the calendar, or when the state should survive Root
unmounting. Everything here is exported from @moltenship/calendar-solid. The store has no
framework in it.
createCalendarStore
import { createCalendarStore, createStateSelector } from "@moltenship/calendar-solid";
import { seed, weekRules } from "./app";
import { Calendar, type View } from "./calendar";
export const store = createCalendarStore<View>({
defaultView: "list",
defaultAnchorDate: Temporal.PlainDate.from("2026-10-08"),
defaultTimeZone: "Europe/Berlin",
});
store.actions.setAnchorDate(Temporal.PlainDate.from("2026-10-15"));
console.log(store.getSnapshot().anchorDate.toString()); // 2026-10-15Prop
Type
The type arguments are <TView, TSelection, TFocus, TResourceId>. The store has three members:
actions:setView,setAnchorDate,setTimeZone,setSelection,setFocus, andsetExpandedResourceIds. Each takes the new value and, optionally,{ event?, reason?, source? }(CalendarCommandOptions), which a mountedRootpasses on to its change handler.getSnapshot(): the current state as one frozen object. It's a new object after each change.subscribe(listener): callslistenerafter each change and returns an unsubscribe function.
createStateSelector(store, select, options?) returns an accessor of one value from the store, so
any component can read it, inside Root or not. It updates only when that value changes, by
options.isEqual when you pass one:
export function AnchorDate() {
const anchorDate = createStateSelector(store, (state) => state.anchorDate, {
isEqual: (a, b) => a.equals(b),
});
return <time>{anchorDate().toString()}</time>;
}Sharing a store with Root
Pass the store to Root with the store prop:
function JumpToHolidays() {
return (
<button
type="button"
onClick={() => store.actions.setAnchorDate(Temporal.PlainDate.from("2026-12-24"))}
>
Holidays
</button>
);
}
export function Page() {
return (
<>
<JumpToHolidays />
<Calendar.Root
store={store}
events={seed}
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
defaultTimeZone="Europe/Berlin"
locale="en-US"
weekRules={weekRules}
>
<Calendar.ActiveView />
</Calendar.Root>
</>
);
}Rootshows the store's values. TypeScript still asks fordefaultAnchorDateanddefaultTimeZone, butRootignores them when it has a store.store.actionsgo through the mountedRoot: controlled props stay controlled, and their change handlers run. If several mounted roots share the store, the most recently mounted one handles them. A handler hears such a call withreason: "imperative"andsource: "programmatic", and can stop it withcancel().- An agent's changes go through the same store. The store has no agent API of its
own: agents reach the calendar through the mounted
Root. getSnapshot()returns the values the store holds. A value you control with a prop lives in your own state, not in the store.- Unmounting
Rootleaves the store as it was.