简体   繁体   中英

How to use NativeBase DatePicker

Given this DatePicker Api from NativeBase v2.5.1 how am I supposed to capture the change date event with the new selected date?

If I understand well the selected date is only available in the internal state of the component:

setDate(date) {
    this.setState({ chosenDate: new Date(date) });
}

I imagine I can use the react native ref api but it doesn't seem right since other similar components do offer the onDateChange event, eg: react-native-datepicker

Fixed in native-base v2.6.1 onwards.

<DatePicker
formatChosenDate={date => {return moment(date).format('YYYY-MM-DD');}}
..... />

You can set,

onDateChange={(date) => this.setDate(date)}

and make sure you have updated the native-base version to to v2.6.1

Check out : v2.6.1

import {DatePicker} from 'native-base'

        this.state = {
            date : ''
        }
    render(){
        console.log('selected date',this.state.date)
        render(
            <View>
                <DatePicker
                    defaultDate={new Date(1994, 3, 23)}
                    // minimumDate={new Date()}
                    textStyle={'#000'}
                    placeHolderTextStyle={'#000'}
                    onDateChange={(date) => this.setState({ date })}
                 />
            </View>
        )
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM