I have a datepicker from the npm plugin i react-native-date-picker and it works without problems but I need that when selecting the date it returns the date that I select in the input field but I have not been able to do it.
import React, { useState } from 'react'
import { Button } from 'react-native'
import DatePicker from 'react-native-date-picker'
export default () => {
const [date, setDate] = useState(new Date())
const [open, setOpen] = useState(false)
return (
<>
<Button title="Open" onPress={() => setOpen(true)} />
<DatePicker
modal
open={open}
date={date}
onConfirm={(date) => {
setOpen(false)
setDate(date)
}}
onCancel={() => {
setOpen(false)
}}
/>
</>
)
}
I had the same problem and I scrambled it like this:
Apparently you can't display a Date in JSX so I did the following:
When I wanted to save the date, I sent it to a method that transforms it into a string so I can display it.