title: how to open DatePicker on Button Click in React Native
body: <p>I wanted to know how we can display datepicker on button click in react native. I have tried various solutions still no success,Any help would be helpful.
  thank you.</p>
  <p>Below is what i tried</p>
  <pre><code>import React, { Component } from 'react';
  import {
  Platform,
  StyleSheet,
  View,DatePicker
  } from 'react-native';
  </code></pre>
  <blockquote>
  <p>This is my render method</p>
  </blockquote>
  <pre><code>render(){
      return(
          &lt;TouchableOpacity
          onPress={() =&gt; this.datePicker.onPressDate()}&gt;
          &lt;Text&gt;
           Hello Date
          &lt;/Text&gt;
      &lt;/TouchableOpacity&gt;
      
    &lt;DatePicker
      style={{width: 200}}
      ref={(picker) =&gt; { this.datePicker = picker; }}
      date={this.state.date}
      mode=&quot;date&quot;
      placeholder=&quot;Select date&quot;
      format=&quot;YYYY-MM-DD&quot;
     minDate=&quot;2016-05-01&quot;
     maxDate=&quot;2020-12-12&quot;
     confirmBtnText=&quot;OK&quot;
     cancelBtnText=&quot;Cancel&quot;
     onDateChange={(date) =&gt; {this.setState({date: date})}}
    
      /&gt;     
      );
  }
  </code></pre>
  <blockquote>
  <p>whenever i run i get below error</p>
  </blockquote>
  <p><img src="https://i.stack.imgur.com/R3Vaj.png" alt="" /></p>