-
-
Notifications
You must be signed in to change notification settings - Fork 196
Upgrade guide for React Date Picker ≤5 users
React-Date-Picker 6.0 comes with entirely different architecture, but for most use cases, upgrading should be fairly easy. Benefits from upgrading are substantial - React-Date-Picker 6.0 is built on modern web technologies and does not need dependencies like moment.js.
If you used React-Date-Picker simply for picking dates inside a form, you can update in less than 5 minutes.
- Instead of including
DateField
andCalendar
in your application, just doimport DatePicker from 'react-date-picker'
. React-Date-Picker will handle opening the calendar automatically. - Pass
date
prop asDate()
. For example, instead of writingdate="2017-09-30"
writedate={new Date(2017, 8, 30)}
. -
onChange
callbacks instead of three arguments (dateString, dateMoment, timestamp) has just one argument,Date()
.- If you need a stringified date, you can use the following solutions:
- For ISO format:
date.toISOString()
will return"2017-09-30T00:00:00.000Z"
- Local formats:
- User's default date format:
date.toLocaleDateString()
will return user's default date format, for example"30.09.2017"
. - Other local formats:
date.toLocaleDateString('en-US') will return date formatted for en-US locale,
"9/30/2017"`.
- User's default date format:
- All others: You can use custom solutions or use libraries like moment.js.
- For ISO format:
- If you need a moment.js date, just write
const dateMoment = moment(date)
. - If you need a timestamp, just write
const timestamp = date.getTime()
.
- If you need a stringified date, you can use the following solutions:
- Don't pass
dateFormat
prop. Date format is now automatically determined based onlocale
prop. For example, setting it toen-US
will set the date format toMM/DD/YYYY
. - Don't pass
weekStartDay
prop. Week start day is now automatically determined based onlocale
prop. If you wish to forcibly change it anyway, setcalendarType
toUS
orISO 8601
, depending on which calendar you would like to have displayed.
React-Date-Picker's architecture is now rebuilt from the ground up. React-Date-Picker now provides you with just one component: DatePicker. This is a counterpart of DateField component in React-Date-Picker 5.
If you wish to use just the calendar, check out React-Calendar. It's the calendar used internally in React-Date-Picker. By splitting the architecture I believe I can keep components more generic and because of that, more useful for the community.
If you used moment.js only for React-Date-Picker 5.0, you can safely remove it. React-Date-Picker relies only on native ECMAScript functionalities.
React-Date-Picker is just responsible for creating an interactive date input field. It uses React-Calendar to provide users with calendar UI after they focus on date input field. You will find them there!
Tiles for Saturday and Sunday have their own className, react-calendar__month-view__days__day--weekend
. If you want them highlighted, just apply styles of your choice to this class.
Alternatively, you can use tileClassName
function to pass custom class for weekend dates:
tileClassName={({ date, view }) => view === 'month' && (date.getDay() === 0 || date.getDay() === 6) ? 'weekend' : null}
## How do I choose date ranges?
Unfortunately, React-Date-Picker does not support choosing date ranges in one component. This is my #1 priority when I'll have a sufficient amount of time for implementing this.