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

193
Views
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 answers
Answer question

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 Report

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 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!