Reputation: 973
I am trying to implement this date-picker in my application: https://www.npmjs.com/package/react-date-picker
I've initialized the component like this:
<Grid item xs={7}>
<DatePicker
name="Date"
value={this.getDate}
onChange={this.handleDateChange}
/>
</Grid>
the value function returns the date and looks like this:
getDate = () => {
const dateToday = Service.todaysDate //service returns a string so we convert
return new Date(dateToday)
}
but I get this typescript error which doesn't make any sense!!
Type '() => Date' is not assignable to type 'Date | Date[] | undefined'. Type '() => Date' is missing the following properties from type 'Date[]': pop,
I am new to react and I am having trouble figuring this whole this out. Any help is appreciated. Thank You.
Upvotes: 1
Views: 1466
Reputation: 2403
You should bind values with actual js variables not function. Moreover events should be bound to lambda expression. So in your render() function you should add
let date = this.getDate();
return (<Grid item xs={7}>
<DatePicker
name="Date"
value={date}
onChange={(event) => this.handleDateChange(event)}
/>
</Grid>);
Upvotes: 1