You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Keep in mind that these are the styles from flatpickr package// See troubleshooting section in case you have problems importing the stylesimport"flatpickr/dist/themes/material_green.css";importFlatpickrfrom"react-flatpickr";import{Component}from"react";classAppextendsComponent{constructor(){super();this.state={date: newDate()};}render(){const{ date }=this.state;return(<Flatpickrdata-enable-timevalue={date}onChange={([date])=>{this.setState({ date });}}/>);}}
Basic props
defaultValue
string | optional
This is the default value that will be passed to the inner input
value
string || array || object || number | optional
Same as below
options
Object | optional
Flatpickr options: you can pass all Flatpickr parametershere.
All Flatpickrhooks can be passed within this option too.
Example:
<Flatpickroptions={{minDate: "2017-01-01"}}/>
children
node | optional
This option is closely related with the wrap option from Flatpickr, please refer to the former link for more information.
className
string | optional
Custom className that will be applied to the inner input element. In case you need to modify the rendered input styles this is the prop you should use.
Event handlers
The following props are provided in order to customize the Flatpickr's functions default behaviour. Please refer to the Events & Hooks section from Flatpickr library.
onChange
function | optional
onOpen: function
function | optional
onClose: function
function | optional
onMonthChange: function
function | optional
onYearChange: function
function | optional
onReady: function
function | optional
onValueUpdate: function
function | optional
onDayCreate: function
function | optional
onDestroy: function
function | optional
Advanced props
render prop
function | optional
Use this prop if you want to render your custom component, this is a Render props pattern.
Please import themes directly from the flatpickr dependency.
Troubleshooting
Help, the Date Picker doesn't have any styling!
In most cases, you should just be able to import 'flatpickr/dist/themes/airbnb.css', but in some cases npm or yarn may install flatpickr in node_modules/react-flatpickr/node_modules/flatpickr. If that happens, removing your node_modules dir and reinstalling should put flatpickr in the root node_modules dir, or you can import from react-flatpickr/node_modules/flatpickr manually.
The Date Picker closes after a value is selected
This occurs due to the date picker being created and destroyed on each render. To avoid this, you need
to ensure that any props and options that are passed in are memoized with useMemo. You should also
ensure that your event handlers have stable references by wrapping them in useCallback.