Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda