here i am providing my sample example working on codesandbox. How to reset a datepicker value after submitting a form?
state = {
setFieldValue: ''
}
onChange = (setFieldValue) => {
this.setState({ setFieldValue: null })
}
render() {
const { values, handleSubmit } = this.props
return (
name="dateofbirth"
label="dateOfBirth"
component={DateInput}
formitemlayout={formItemLayout}
value={this.state.setFieldValue}
onChange={this.onChange}
/>
htmlType="submit">Submit
}
my working codesandbox link is enter link description here
解决方案
Instead of adding empty strings as it raises a propType error its best to use null
onChange={(date, dateString) =>
setFieldValue("dateofbirth", dateString)
}
value={dateofbirth !== "" ? moment(dateofbirth) : null}
/>