I'm using React-Datepicker and MomentJS. But when I want to use Moment for setting a startDate, the value gives Invalid date in the datepickerfield.
When I log the this.state.startDate in the console, the console shows me the following: "startdate: 27-11-2018", this has the format 'DD-MM-YYYY'. This format is also used for the DatePicker component.
import * as React from "react";
import * as ReactDOM from "react-dom";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import * as moment from "moment";
import "moment/locale/nl";
export class DateContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
startDate: moment().format('DD-MM-YYYY'),
};
}
render() {
console.log('startdate:',this.state.startDate);
return (
<div className="date-Filter">
<div className="date-Filter-Title">Release Date</div>
<DatePicker
onChange={this.handleStartDate}
selected={this.state.startDate}
dateFormat="DD-MM-YYYY"
isClearable={true}
placeholderText="Select a date other than today or yesterday"
fixedHeight={true}
tetherConstraints={ [] }
locale="nl"
popperPlacement="right-start"
popperModifiers={{
flip: {
enabled: false
},
preventOverflow: {
enabled: true,
escapeWithReference: false
}
}}
selectsStart
startDate={this.state.startDate}
className="startDate"
showMonthDropdown
showYearDropdown
/>
</div>
);
}
}
Can someone explain to me why it is showing invalid date in browser.
My Dependencies:
"dependencies": {
"moment": "^2.22.2",
"react": "^16.6.0",
"react-datepicker": "^2.0.0",
"react-dom": "^16.6.0",
"sass-loader": "^7.1.0",
"searchkit": "^2.3.1-alpha.4"
},