1.0.1 • Published 1 year ago

@tounsoo/usecalendar v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

NameTypeDefault Value
valueTemporal.PlainDateTemporal.Now.plainDateIS()
calendarstringnew Intl.DateTimeFormat().resolvedOptions().calendar

Return

This extends Temporal.PlainYearMonth.

NameType
weeksuseCalendarDay
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
1.0.1

1 year ago

1.0.0

1 year ago