Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 1.45 KB

README.md

File metadata and controls

60 lines (39 loc) · 1.45 KB

useCalendar

Custom Hook for Calendar

This is a custom hook that uses Temporal to return calendar objects.

Currently using polyfill as Temporal is in stage 3

API

Parameters

Name Type Default Value
value Temporal.PlainDate Temporal.Now.plainDateIS()
calendar string new Intl.DateTimeFormat().resolvedOptions().calendar

Return

This extends Temporal.PlainYearMonth.

Name Type
weeks useCalendarDay[][]
nextMonth () => void
prevMonth () => void

Examples

Getting Month Year String

import { useCalendar } from "@tounsoo/usecalendar";

const cal = useCalendar("2023-01-17");

const monthString = cal.toLocaleString("en-US", {
  month: monthFormat,
});
const yearString = cal.toLocaleString("en-US", {
  year: yearFormat,
});

const Header = `${monthString} ${yearString}`;
// ^ January 2023

Changing Month

import { useCalendar } from "@tounsoo/usecalendar";

const cal = useCalendar("2023-01-17");

const monthString = cal.month; // -> 1

cal.nextMonth();

const afterChange = cal.month; // -> 2