calendar-creator
v1.0.16
Published
Minimal hook for creating calendars
Downloads
6
Readme
useCalendar
(useCalendar name was taken 😢 so it goes under calendar-creator)
Minimal hook for generating logic for calendars
Example use
- Initializing calendar
import { useCalendar } from 'calendar-creator'
const { interval, monthInText } = useCalendar({ inputDate: new Date() })
- Using with Locale and custom dateFormat
/* Locales are imported seperately from date-fns
and not included in package */
import fr from 'date-fns/locale/fr'
const {decrement, increment, interval, monthInText } = useCalendar({
inputDate: new Date(),
dateFormat: 'dd/MM/yyyy',
locale: fr
})
Using calendardata
- Map over interval
- Use provided formatterfunc to apply default or provided format
const App = () => {
const { interval, formatter } = useCalendar({ inputDate: new Date(), dateFormat: 'dd/MM/yyyy' })
return (
<div>
{interval.map((date) => (
{/* Date will be formatted to dd/MM/yyyy */}
<div key={date.getTime()}>{formatter(date)}</div>
))}
</div>
)
}