question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger onDatesChange only when BOTH dates are selected

See original GitHub issue

Current behaviour for DateRangePicker is that onDatesChange is triggered on EVERY date select, to and from

How to trigger onDatesChange only when BOTH dates has been selected? I know I can compare new and current dates, but I want to avoid this kind of hacking. It there some out of the box approaches?

`to` => `from` => onDatesChange( only now it is triggered )

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
furkantanyolcommented, Jul 12, 2019

Here is my solution:

  const [stateStartDate, updateStateStartDate] = useState(null)
  const [stateEndDate, updateStateEndDate] = useState(null)

  const refreshDates = () => {
    updateStateStartDate(null)
    updateStateEndDate(null)
  }

const updateDateData = async ({ startDate, endDate }) => {
    if (focusedInput === 'startDate') {
      refreshDates()
      updateStateStartDate(startDate)
      return
    }
    if (focusedInput === 'endDate') {
      updateStateEndDate(endDate)
    }

    if (stateStartDate && stateEndDate) {
      // DO STUFF
      updateFocusedInput(null)
      // DO STUFF
      }
    }
  }

<DateRangePicker
      .
      .
   startDate={stateStartDate}
   endDate={stateEndDate}
   onDatesChange={updateDateData}
      .
      .
      />
1reaction
linorabolinicommented, Apr 23, 2018

@majapw hey im saying the same thing. It should be logic that the parent component should handle ! i just provided the snippet haahah

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trigger onDatesChange only when BOTH dates are selected
Current behaviour for DateRangePicker is that onDatesChange is triggered on EVERY date select, to and from How to trigger onDatesChange only ...
Read more >
How can I trigger a method when end date is changed
You need to use onFocusChange and onDatesChange props of <DateRangePicker> , and also componentDidUpdate() React lifecycle method:.
Read more >
react-dates - npm
You can control the selected dates using the startDate , endDate , and onDatesChange props as shown below. The DateRangePicker also manages ...
Read more >
Date Range Picker — JavaScript Date & Time Picker Library
singleDatePicker : (true/false) Show only a single calendar to choose one date, instead of a range picker with two calendars. The start and...
Read more >
react-dates-patched-x0r - npm package - Snyk
You can control the selected dates using the startDate , endDate , and onDatesChange props as shown below. The DateRangePicker also manages ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found