Reputation: 1015
I have implemented to pick and view the date as following ,
const [pickDate, setPickDate] = useState(new Date());
const onChange = (event, selectedDate) => {
const currentDate = selectedDate || date;
setShow(Platform.OS === 'ios');
setDate(currentDate);
setPickDate(selectedDate);
};
<View>
<View>
<Button onPress={showDatepicker} title="Show date picker!" />
</View>
<View>
<Button onPress={showTimepicker} title="Show time picker!" />
</View>
{show && (
<DateTimePicker
testID="dateTimePicker"
value={date}
mode={mode}
is24Hour={true}
display="default"
onChange={onChange}
/>
)}
<Text>{pickDate}</Text>
</View>
</View>
But I have got the following error when after the pick the date.
Can anyone suggest the solution ?
Upvotes: 3
Views: 569
Reputation: 1319
As per the official documentation, the date should be in the string format.
Like "2016-05-15"
, what you seem to pass a Date object. const [pickDate, setPickDate] = useState(new Date());
Kindly replace date object with the string, that will surely work.
Ref: https://github.com/xgfe/react-native-datepicker
Upvotes: 1