0
Fork 0
mirror of https://github.com/TanStack/time.git synced 2026-11-16 19:09:47 +00:00
time/docs/quick-start.md
Bartłomiej Krakowski 71e8c5a8e9
docs: basic docs
2026-08-24 12:50:54 +02:00

2.7 KiB

title id
Quick Start quick-start

Quick Start

TanStack Time exposes a headless core and framework adapters. Pick the section that matches your stack.

Core Usage

Create a calendar, add events, and read the current state.

import { createCalendar, calendarFeatures, stockFeatures } from '@tanstack/time'

const calendar = createCalendar({
  viewMode: { value: 1, unit: 'week' },
  timeZone: 'UTC',
  features: calendarFeatures(stockFeatures),
  events: [
    {
      id: '1',
      title: 'Team Standup',
      start: '2024-03-18T09:00:00',
      end: '2024-03-18T10:00:00',
    },
  ],
})

console.log(calendar.getEvents())
console.log(calendar.getDays())

React Usage

Use the useCalendar hook to create a reactive calendar inside a component.

import { useCalendar } from '@tanstack/react-time'
import { calendarFeatures, stockFeatures } from '@tanstack/time'

function MyCalendar() {
  const calendar = useCalendar({
    viewMode: { value: 1, unit: 'week' },
    timeZone: 'UTC',
    features: calendarFeatures(stockFeatures),
    events: [
      {
        id: '1',
        title: 'Team Standup',
        start: '2024-03-18T09:00:00',
        end: '2024-03-18T10:00:00',
      },
    ],
  })

  return (
    <div>
      <button onClick={calendar.goToPreviousPeriod}>Previous</button>
      <button onClick={calendar.goToNextPeriod}>Next</button>
      <ul>
        {calendar.getEvents().map((event) => (
          <li key={event.id}>
            {event.title} — {event.start} to {event.end}
          </li>
        ))}
      </ul>
    </div>
  )
}

Solid Usage

Use the createCalendar primitive to build a reactive calendar.

import { createCalendar } from '@tanstack/solid-time'
import { calendarFeatures, stockFeatures } from '@tanstack/time'

function MyCalendar() {
  const { calendar, state } = createCalendar({
    viewMode: { value: 1, unit: 'week' },
    timeZone: 'UTC',
    features: calendarFeatures(stockFeatures),
    events: [
      {
        id: '1',
        title: 'Team Standup',
        start: '2024-03-18T09:00:00',
        end: '2024-03-18T10:00:00',
      },
    ],
  })

  return (
    <div>
      <button onClick={calendar.goToPreviousPeriod}>Previous</button>
      <button onClick={calendar.goToNextPeriod}>Next</button>
      <ul>
        {state().events.map((event) => (
          <li>{event.title} — {event.start} to {event.end}</li>
        ))}
      </ul>
    </div>
  )
}

Next Steps