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

205
Vistas
Can I put a conditional here in the value?

I wanted to have the initial datepicker to get the date of today of which I can already do, at this point, selected2Date still does not exist. Then, I want to check in the value if selected2 was true and instead of displaying the date of today, it will display the date of selected2Date.

 const [selected2, setSelected2Date] = useState(new Date()); 

The code if selected2Date is still empty.

                          <MuiPickersUtilsProvider utils={DateFnsUtils}>
                                  <DatePicker
                                    format="MM/dd/yyyy"
                                    value={selected2}
                                    onChange={setSelected2Date}
                                    fullWidth
                                  />
                                </MuiPickersUtilsProvider>

The code if selected2Date is not empty. Can I put a conditional here in the value?

 <MuiPickersUtilsProvider utils={DateFnsUtils}>
                                      <DatePicker
                                        format="MM/dd/yyyy"
                                        value={user.choices?.selected2}
                                        onChange={setSelected2}
                                        fullWidth
                                      />
                                    </MuiPickersUtilsProvider>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

  <DatePicker
   format="MM/dd/yyyy"
   value={user.choices ? user.choices : selected2}
   onChange={setSelected2}
   fullWidth
  />             

try this or if you are geting value from user,choices.selected2 then

<DatePicker
   format="MM/dd/yyyy"
   value={user.choices ? user.choices.selected2 : selected2}
   onChange={setSelected2}
   fullWidth
  />         
                    
about 4 years ago · Juan Pablo Isaza Denunciar

0

If value exist in user.choices.selected2 then get from the user.choices.selected2 otherwise get from the selected2 !

try below code.

<MuiPickersUtilsProvider utils={DateFnsUtils}>
  <DatePicker
    format="MM/dd/yyyy"
    value={user.choices.selected2 ? user.choices.selected2 : selected2}
    onChange={setSelected2}
    fullWidth
  />
</MuiPickersUtilsProvider>
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