I got an issue while working with date input in react. so the date value is coming from graphQL and format of date is dd.mm.yyyy but in order to set a default value for HTML date input I am converting format to yyyy.mm.dd and for saving data again I need to do vice versa.
I am saving date in state and calling on change function to update values and converting formats.
the problem is that this function is being triggered twice onChange and returning NaN-NaN-NaN (on 2nd run) but not each time only sometimes (weird). And, with some dates, it works fine, for example, with 02.03.2000 no error and executed only once.
with 24 it called twice and error on 2nd call (see screenshot). maybe conversion is wrong somehow? and if I remove defaultValue from input then it called only once.
state = { newUser: { geburtsdatum: "01.02.2000" } } ConvertDate(htmlDate, format) { var date = new Date(htmlDate); var dd = date.getDate(); var mm = date.getMonth() + 1; var yyyy = date.getFullYear(); if (dd < 10) { dd = "0" + dd; } if (mm < 10) { mm = "0" + mm; } if (format === "graphql") date = dd + "." + mm + "." + yyyy; if (format === "html") date = yyyy + "-" + dd + "-" + mm; return date; } onChange = e => { let value = e.target.value; let name = e.target.name; if (e.target.type === "date") { value = this.convertDate(value, "graphql"); console.log(value, name); } this.setState(prevState => { return { newUser: { ...prevState.newUser, [name]: value } }; }); }; <input type="date" name="geburtsdatum" defaultValue={this.convertDate(this.state.newUser.geburtsdatum, "html")} onChange={this.onChange} placeholder={this.getDJHTooltip("geburtsdatum")} /> 
ConvertDate? A functional component? there is noreturnmethodrenderfunction? what is this<inputelement in the middle of the code, without any context?