adriam
adriam

Reputation: 451

(ReactJS) How do you get the input value of an input of type date?

I currently have

<input type="date" onChange={(input) => { _this.setState({startDate: input})}}/>

No matter what I've been changing around (the onChange part to ref etc etc), startDate shows up as undefined when I console.log my state. I've even changed startDate:input to startDate:input.value and it still hasn't worked.

I tried using many react libraries such as react-datepicker and etc. So far they haven't really been working out for me(We have a ton of CSS and their CSS is messed up due to that issue).

Upvotes: 3

Views: 15264

Answers (1)

Arman Charan
Arman Charan

Reputation: 5797

Not sure what _this is.

I'd recommend checking out the MDN reference on input events to get an idea of what they are / how to intercept them.

See below for a working example.

<input type="date" onChange={(event) => this.setState({startDate: event.target.value})}/>

Upvotes: 8

Related Questions