Ask Your Question
1

In the Child-Component, what is the method to obtain the Date from "react-native-datepicker"?

asked 2023-07-13 23:49:11 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-14 00:13:02 +0000

scrum gravatar image

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}
      />
    );
  }
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-13 23:49:11 +0000

Seen: 7 times

Last updated: Jul 14 '23