Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

johanwennerstrom-joj/useCalendar

Repository files navigation

npm

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>
	)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published