title: How Pass Data to Parent Component React Native
body: <p>I am new to react native and I am developing my final year project using it.
  I am facing an issue when trying to get the value of a child component.
  I made my own component out of DateTimePicker (displaying only the date), and then I am using this date picker in another screen.
  When selecting a new value using the picker I want to store this new value in the parent state.
  I did some research online and found that I need to pass the data from the child to the parent. I tried doing that but now I am getting the below error:</p>
  <pre><code>[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_this.props.onSelectDate')]
  </code></pre>
  <p>You can find my code below:
  Parent component:</p>
  <pre><code>import { Button, StyleSheet, Text, TextInput, View, TouchableWithoutFeedback, Keyboard} from &quot;react-native&quot;;
  import RadioForm, {RadioButton, RadioButtonInput, RadioButtonLabel} from 'react-native-simple-radio-button';
  
  import AppDatePicker from '../components/AppDatePicker';
  import AppTimePicker from '../components/AppTimePicker';
  
  var radio_field_type = [
    {label: 'Natural Turf', value: 0 },
    {label: 'Artificial Turf', value: 1 }
  ];
  
  class CreateGameScreen extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        gameDate: &quot;&quot;
      }
    }
    handleNewDate(dateValue) {
      this.setState({gameDate: dateValue});
    }
    render() {
      return (
    &lt;TouchableWithoutFeedback 
    onPress={() =&gt; Keyboard.dismiss()}&gt;
    &lt;View style={styles.container}&gt;
       &lt;View style={styles.header}&gt;
          &lt;Text style={styles.headerTitle}&gt;
              &lt;Text style={{color: 'black'}}&gt;Create Game&lt;/Text&gt;
          &lt;/Text&gt;
      &lt;/View&gt;
      &lt;View style={{margin: 3}}&gt;
      &lt;AppDatePicker style={styles.pickerButton}
        onSelectDate={this.handleNewDate}
      &gt;&lt;/AppDatePicker&gt;
      &lt;Text&gt;{this.state.gameDate}&lt;/Text&gt;
      &lt;/View&gt; 
    &lt;/View&gt;
    &lt;/TouchableWithoutFeedback&gt;
    );
    }}
  
  export default CreateGameScreen;
  </code></pre>
  <p>And here is the child code:</p>
  <pre><code>import {View, Button, Platform, TouchableOpacity, Text} from 'react-native';
  import DateTimePicker from '@react-native-community/datetimepicker';
  import { MaterialCommunityIcons } from '@expo/vector-icons';
  
  export const AppDatePicker = (props) =&gt; {
    const [date, setDate] = useState(new Date(1598051730000));
    const [mode, setMode] = useState('date');
    const [show, setShow] = useState(false);
  
    const handleOnChange = (event, selectedDate) =&gt; {
      const currentDate = selectedDate || date;
      this.props.onSelectDate(currentDate);
      setShow(Platform.OS === 'ios');
      setDate(currentDate);
    };
  
    const showMode = (currentMode) =&gt; {
      setShow(true);
      setMode(currentMode);
    };
  
    const showDatepicker = () =&gt; {
      showMode('date');
    };
  
    return (
      &lt;View&gt;
        &lt;View&gt;
          &lt;TouchableOpacity onPress={showDatepicker} style={{borderWidth: 1, borderColor: 'black', flexDirection: 'row',   height: 40}}&gt;
          &lt;Text style={{marginBottom: 6, fontSize: 16,marginLeft: 10, alignSelf: 'center'}}&gt;Please select the game date&lt;/Text&gt;
          &lt;View style={{position: 'absolute', right: 0, alignSelf: 'center'}}&gt;
          &lt;MaterialCommunityIcons name=&quot;calendar&quot; size={35} color=&quot;black&quot;/&gt;
          &lt;/View&gt;
          &lt;/TouchableOpacity&gt;
        &lt;/View&gt;
        {show &amp;&amp; (
          &lt;DateTimePicker
            testID=&quot;dateTimePicker&quot;
            value={date}
            mode={mode}
            is24Hour={true}
            display=&quot;default&quot;
            onChange={handleOnChange}
          /&gt;
        )}
      &lt;/View&gt;
      
    );
  };
  
  export default AppDatePicker;
  
  </code></pre>
  <p>I would really appreciate any help. Thanks in advance</p>