1.0.2 • Published 2 years ago
use-calendar-react-hook v1.0.2
useCalendar React Hook
useCalendar is a React Hook written in TypeScript that generates calendar data. This hook is a utility that helps you to create flexible and customizable calendar-based components.
Installation
npm install use-calendar-react-hook
# or with yarn
yarn add use-calendar-react-hookUsage
Import useCalendar from the package and use it in your component:
import useCalendar from "use-calendar-react-hook";
function App() {
const {
today,
currentScope,
selectedDate,
currentMonth,
selectDate,
navigateMonth,
} = useCalendar();
// Use these variables and functions to build your calendar UI
return <div>...</div>;
}API
useCalendar()
The useCalendar hook generates and returns the following data and functions:
today: The current datecurrentScope: An array of objects representing the dates to be displayed in the calendar. Each object has adatestring, and optionalisCurrentMonth,isToday, andisSelectedbooleans.selectedDate: The currently selected datecurrentMonth: The current month that the calendar is displayingselectDate(date: Date): A function that sets the selected datenavigateMonth(offset: number): A function that changes the current month by the provided offset (positive for future months, negative for past months)
License
MIT