Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
react native DateTimePicker set initial state to String

I'm trying to implement react-native-datetimepicker and i want to set an initial state text "Edit Date of Birth" instead of current today Date, can anyone guide me on how to achieve that? It seems that i can't use a string as a value in the date hook.

  const [date, setDate] = useState(new Date());
  const [mode, setMode] = useState('date');
  const [show, setShow] = useState(false);

  const onChange = (event, selectedDate) => {
    const currentDate = selectedDate || date;
    setShow(Platform.OS === 'ios');
    setDate(currentDate);
  };

return (
<Text>{date.toDateString()}</Text>
<DateTimePicker
              testID="dateTimePicker"
              value={date}
              mode={mode}
              is24Hour={true}
              display="default"
              onChange={onChange}/>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need a Text/Button component displaying the message if you don't have a selected date (Initialized as null) yet.

const [date, setDate] = useState(null);
const [show, setShow] = useState(false);

const showDate = () => {
   setShow(true)
}

const onChange = (event, selectedDate) => {
   const currentDate = selectedDate || date;
   setShow(Platform.OS === 'ios');
   setDate(currentDate);
};

return (

<View>
<Button onPress={showDate} title={ date ? date.toDateString() : 'Edit Date of Birth'} />

{show && ( 
   <DateTimePicker 
       testID="dateTimePicker" 
       value={date} 
       is24Hour={true} 
       display="default" 
       onChange={onChange}/> 
}
</View>

)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda