I am using react-native-community/datetimepicker
to select a date. It works fine when I select a date for the first time. But if I again try to open datepicker then it is giving me error.
Below is my code:
const currentDate = Moment();const [show, setShow]: any = useState(false);const [changedDate, setChangedDate] = useState<string | null>(null);const onChange = (event: any, selectedDate: any) => { setShow(Platform.OS === 'ios'); setDate(currentDate); var dateInLocal = selectedDate.toLocaleDateString().replace('/', '-'); console.log(dateInLocal); setChangedDate(dateInLocal);};<View><Text>{changedDate}</Text><TouchableOpacity onPress={() => { setShow(true); }}><Text>open</Text></TouchableOpacity></View>{show && (<DateTimePicker testID="dateTimePicker" value={ changedDate ? new Date(changedDate) : currentDate.toDate() } mode="date" is24Hour={true} display="default" onChange={onChange} />)}
Works fine when selecting date for time, below is the error which I am getting when I am trying open datepicker for second time:
I am not able to understand what I am doing wrong..please help