Skip to content

tounsoo/useCalendar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

React hook for calendar using Temporal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published