The method to obtain the Date from "react-native-datepicker" in a Child-Component is to use the onDateChange prop. This prop takes a function that will be called whenever the user selects a new date. The function will receive the new date as an argument, which can then be stored in the component's state or passed to a parent component through a callback function. Example:
import DatePicker from 'react-native-datepicker';
class ChildComponent extends React.Component {
state = {
selectedDate: null,
};
handleDateChange = (date) => {
this.setState({ selectedDate: date });
};
render() {
return (
<DatePicker
date={this.state.selectedDate}
mode="date"
onDateChange={this.handleDateChange}
/>
);
}
}
Asked: 2023-07-13 23:49:11 +0000
Seen: 7 times
Last updated: Jul 14 '23