picker icon indicating copy to clipboard operation
picker copied to clipboard

Trigger onOpenChange shouldn't sync with onChange take effect.

Open Luncher opened this issue 3 years ago • 0 comments

demo:

const handleOpenChange =(visible: boolean) => {
    if (visible) {
       return
    }
   // get an old value
    console.log('handleOpenChange', visible, dateRange)
    //...
  }

  const handlePickerChange = ({ start, end }: { start: number, end: number}) => {
    // setState
    setDateRange({ startAt: dayjs(start).unix(), endAt: dayjs(end).unix() })
  }

  const pickerValue = isValidDateRange
    ? { start: dateRange.startAt! * 1000, end: dateRange.endAt! * 1000 }
    : { start: null, end: null }


return (
   <RcRangePick ... />
)

https://github.com/react-component/picker/blob/5306c8938aded49c5d6f6b6d4761ddab25e3cce9/src/RangePicker.tsx#L775-L778

according to the source code above, I think the trigger onOpenChange shouldn't sync with onChange take effect. otherwise, a lways get an old value in onOpenChange.

Luncher avatar May 13 '22 11:05 Luncher