Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
React Native DateTimePicker: ¿Por qué sigue abriéndose después de presionar el botón "Aceptar"?

Estoy tratando de crear un selector de fecha. Cuando el usuario presiona el botón "Aceptar", el modal debería haberse cerrado pero sigue reabriendo. Estoy usando react-native-datetimepicker. Intenté poner setShow(false) cuando se presiona el botón "Aceptar", pero aún se abre por una fracción de segundo.

 const [receiptDate, setReceiptDate] = React.useState(""); const [date, setDate] = React.useState(new Date()); const [today, setToday] = React.useState(new Date()); const [show, setShow] = React.useState(false); const onChange = (event, selectedDate) => { const currentDate = selectedDate || date; setDate(currentDate); if (event.type == "dismissed") { console.log("CANCEL") setShow(false) return null; } else { setShow(false) console.log("OK") let tempDate = new Date(currentDate); let fDate = tempDate.getFullYear() + "-" + tempDate.getDate() + "-" + (tempDate.getMonth() + 1) setReceiptDate(fDate); console.log(fDate); return; } } <View> <TouchableOpacity activeOpacity={0.9} onPress={() => setShow(true)}> <TextInput editable={false} placeholder="YYYY-MM-DD (2022-05-22)" value={receiptDate} /> </TouchableOpacity> {show && ( <DateTimePicker testID='dateTimePicker' value={date} mode={'date'} display='default' onChange={onChange} maximumDate={today} />)} </View>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En mi opinión, no está configurando mostrar en falso, en caso de que el usuario seleccione una opción. Intente esto y avíseme si soluciona su problema o no:

 const onChange = (event, selectedDate) => { if (event.type == 'set') { const currentDate = selectedDate || startDate; let tempDate = new Date(currentDate); let fDate = tempDate.getFullYear() + "-" + tempDate.getDate() + "-" + (tempDate.getMonth() + 1) setReceiptDate(fDate); setDate(currentDate); } setShow(false) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!