Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 828
user2457870 Avatar asked Jun 10 '18 21:06

user2457870


2 Answers

Check docs for Date Picker https://docs.nativebase.io/Components.html#date-picker-def-headref

Sample example from NativeBase KitchenSink https://github.com/GeekyAnts/NativeBase-KitchenSink/blob/master/src/screens/datepicker/index.js

Fixed with v2.5.2

like image 90
Supriya Kalghatgi Avatar answered Oct 05 '22 19:10

Supriya Kalghatgi


Fixed in native-base v2.6.1 onwards.

<DatePicker
formatChosenDate={date => {return moment(date).format('YYYY-MM-DD');}}
..... />
like image 45
Newana Avatar answered Oct 05 '22 19:10

Newana