1.3.0 • Published 2 years ago

react-hook-datepicker v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Hook Date Picker

A set of hooks that allow you to build fully customisable single and range date pickers

Installation

npm install react-hook-datepicker --save

This package depends on react and date-fn. Please make sure you have both installed as well.

useDatePicker Usage

Try in codesandbox

const [selectedDate, setSelectedDate] = React.useState<Date | undefined>()
const [isOpen, setIsOpen] = React.useState<boolean>(false)

const {
  calendar,
  getDateProps,
  getPrevMonthButtonProps,
  getNextMonthButtonProps,
} = useDatePicker({ value: selectedDate, isOpen, onChange: setSelectedDate })

Options

NameTypeDescription
valueDate | undefinedThe current selected date. This can be undefined initially
isOpenbooleanShould be truthy when the calendar is open
onChangefunctionCalled when the user selects a date
disabledWhenfunctionUsed to disable dates. It expects a boolean to be returned

Returned Props

NameTypeDescription
visibleDateDateThe date that is currently visible
calendarCalendarAn object that allows you to construct the calendar view
getDatePropsfunctionReturns props that should be applied to each date element you render
getPrevMonthButtonPropsfunctionReturns props that should be applied to the button for viewing the previous month
getNextMonthButtonPropsfunctionReturns props that should be applied to the button for viewing the next month

Calendar Type

NameTypeDescription
datesDate[]An array of dates in the current month
monthstringThe current month
yearnumberThe current year
firstDayOfMonthnumberThe first weekday of the year as an integer. Sunday = 1, Monday = 2

useDateRangePicker Usage

Try in codesandbox

type Range = { start: Date | undefined; end: Date | undefined; }

const [selectedRange, setSelectedRange] = React.useState<Range>({ start: undefined, end: undefined })
const [isOpen, setIsOpen] = React.useState<boolean>(false)

const {
  calendars,
  getDateProps,
  getPrevMonthButtonProps,
  getNextMonthButtonProps,
} = useDateRangePicker({ value: selectedRange, isOpen, onChange: setSelectedRange })

Options

NameTypeDescription
valueDateRange | undefinedThe current selected range. This can be undefined initially
isOpenbooleanShould be truthy when the calendar is open
onChangefunctionCalled when the user selects a date
disabledWhenfunctionUsed to disable before a date. It expects a boolean to be returned

Returned Props

NameTypeDescription
visibleRangeDateRangeThe date range that is currently visible
calendarsCalendar[]An object that allows you to construct the calendar view
getDatePropsfunctionReturns props that should be applied to each date element you render
getPrevMonthButtonPropsfunctionReturns props that should be applied to the button for viewing the previous month
getNextMonthButtonPropsfunctionReturns props that should be applied to the button for viewing the next month

Range Type

NameTypeDescription
startDate | undefinedJS Date format that represents the start of the range
endDate | undefinedJS Date format that represents the end of the range

Calendar Type

NameTypeDescription
view'start' | 'end'A string to identify start of end calendar
datesDate[]An array of dates in the current month
monthstringThe current month
yearnumberThe current year
firstDayOfMonthnumberThe first weekday of the year as an integer. Sunday = 1, Monday = 2 etc
1.2.3

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago