1import React, { useState } from "react";
2import { Button, View } from "react-native";
3import DateTimePickerModal from "react-native-modal-datetime-picker";
4
5const Example = () => {
6 const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
7
8 const showDatePicker = () => {
9 setDatePickerVisibility(true);
10 };
11
12 const hideDatePicker = () => {
13 setDatePickerVisibility(false);
14 };
15
16 const handleConfirm = (date) => {
17 console.warn("A date has been picked: ", date);
18 hideDatePicker();
19 };
20
21 return (
22 <View>
23 <Button title="Show Date Picker" onPress={showDatePicker} />
24 <DateTimePickerModal
25 isVisible={isDatePickerVisible}
26 mode="date"
27 onConfirm={handleConfirm}
28 onCancel={hideDatePicker}
29 />
30 </View>
31 );
32};
33
34export default Example;