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

151
Views
Bidirectional binding from Dropdown to date

On selection of date in the drop down I'm trying to auto-select calendar date, however corresponding auto-selection into date, works only for first selection into dropdown, not on subsequent changes.

Could you advise on why and relevant concept I need to refer back?

enter image description here

const [formValue, setFormValues] =
useState({

  date: null
});

const stringToDate = (data: any) => {
  const date = data.value === "6 Months"
    ? moment().subtract(6, "months")
    : data.value === "Last Month"
      ? moment().subtract(1, "months")
      : moment().subtract(1, "weeks");
  return date.toDate();
}

<GridColumn width={8} className="fullWidth">
          <label>How much back </label>
          <Dropdown
            fluid
            selection
            options={dropdownOptions}
            value={dateDropdownValue}
            onChange={(_e: any, data: any) => {
              setFormValues({
                ...formValue,
                date: stringToDate(data.value),
              });

              setDateDropdownValue(data.value);
            }}
          />
        </GridColumn>
        <GridColumn width={8} className="fullWidth">
          <label>Exact Date is:</label>
          <CalendarWrap>
            <DatePicker
              onChange={(date) => {
                setFormValues({
                  ...formValue,
                  date: date,
                });
              }}                  
              selected={formValue.date}
            />
            <CalendarImg src={Icons.CalendarImage}></CalendarImg>
          </CalendarWrap>
        </GridColumn>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As per my understanding, you should keep track of your dropdown's state in dependency array or useEffect, and once the value changes, call a function to reflect the desired date in Datepicker. I need more information to understand the whole problem

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!