A new decade has begun and a new major version of react-datetime is released. It's been some years since the first release of v2 and a lot has changed in the react ecosystem.
In v3 we have updated the whole base code of react-datetime, catching up with the latest tools and practices. We can proudly say that this is the best performant, most customizable and easiest to understand version of the library so far. This version also makes the mantainance of react-datetime much simpler, this way we are ready to keep shipping new features and improvements.
The easiest way of migrating to v3 is updating the dependency in your package.json:
react-datetime: "^3.0.0"
Then tell npm to start updating in your CLI:
npm update react-datetime
Once the update has finished, try your app.
It might seem to be working ok but some props have changed and, even if they don't break your app, your pickers might be behaving a little bit differently.
We should better search for the following props in our code and replace them as recommended in the points below:
- Search for
defaultValue
prop in your datetime code. Remame it toinitialValue
. - Search for
defaultViewDate
props and replace them withinitialViewDate
. - Search for
viewMode
props and replace them withinitialViewMode
. - Search for
disableCloseOnClickOutside
. If you are using it, replace it withcloseOnClickOutside={false}
. - Search for
<Datetime>
components usingonBlur
oronFocus
. Replace those props withonClose
oronOpen
.onOpen
doesn't receive any parameters anymore, so don't try to access to them. - Search for
onViewModeChange
. If you find it, rename it toonNavigate
. - Search for
Datetime.setView
. If you were using this imperative method, replace it withDatetime.navigate
.
Those are the main changes that might break your app, if you weren't able to find any of those, react-datetime v3 should keep working as usual in your project.
Version 3 is a big refactor of react-datetime. We have tried to not to change the API drastically, but some of the props has been renamed or removed, trying to make them clearer for the developer. A complete list of changes is:
- The props are read directly when possible, not deriving the state from them anymore.
- The props that were used to set initial values, like
defaultValue
,viewDate
orviewMode
are renamed with theinitial
prefix to better express their intention.initialValue
,initialViewDate
,initialViewMode
. disableCloseOnClickOutside
prop is nowcloseOnClickOutside
(avoid double negations).onBlur
andonFocus
props are renamed toonClose
andonOpen
since they had nothing to do with the blur event and it was misleading for some users. If we want to listen to the input'sonBlur
andonFocus
useinputProps
.- Time is not updated anymore on right clicks.
- The new prop
renderView
can be used to customize the whole calendar markup. - The new prop
updateOnView
can be used to decide when to update the date. onViewModeChange
prop has been renamed toonNavigate
when the current view has changed.- We can add a listener to new prop
onBeforeNavigate
in order to detect when the current view is going to change. We can use it to block the navigation or create custom navigation flows. - Two new imperative methods
setViewDate
andnavigate
methods allows to update the current view shown by the app. - Clicking on days from the previous or next month in the days view should work properly now.
- Month, year and time views for locales that don't use gregorian numbers should work properly now.
- A playground has been added to the repo, that makes simpler to work on react-datetime development and test out changes quickly. To run it:
npm run playground
. - Not using the deprecated method
componentWillReceiveProps
anymore. - We are not using create-react-class anymore, bye bye 2016's react!
- Updated typescript definitions.
- Not depending on gulp to create the build anymore.
- Updated most of the dependencies.
react-datetime is made by the community for the community. People like you, interested in contribute, are the key of the project! 🙌🙌🙌
Have a look at our contribute page to know how to get started.