React Native Date Picker

 Run the following command with your project directory

    npm i react-native-modal-datetie-picker @react-native-community/datetimepicker

Code for date picker in react native

    Open App.js in any code editor and replace the code with the following code

App.js

    import React, { Component } from 'react';
    import {
        StyleSheet,
        View,
    } from 'react-native';
    import DateTImePickerModal from 'react-native-modal-datetime-picker';

    export default class App extends Component {

        constructor(props) {
            super(props);
            this.state = {
                isDatePickerVisible: false
            }
        }

        showDatePicker = () => {
            this.setState({ isDatePickerVisible: true });
        } 

        hideDatePicker = () => {
            setDatePickerVisibility(false);
        };
 
        handleConfirm = (date) => {
            console.warn("A date has been picked: ", date);
            hideDatePicker();
        };

        render() {

            const {
                isDatePickerVisible
            } =this.state;

            return(
                <View>
                    <Button title="Show DatePicker" onPress={this.showDatePicker}/>
                     <DateTimePickerModal
                        isVisible={isDatePickerVisible}
                        mode="date"
                        onConfirm={this.handleConfirm}
                        onCancel={this.hideDatePicker}
                      />
                </View>
            );
        }
    }

    To Run the App

    react-native run-andriod



Comments

  1. error ' Invariant Violation: A date or time should be specified as `value`.'

    ReplyDelete

Post a Comment

Popular posts from this blog

React Native Floating Label Textinput

React Native Tab View

React Native Modal box