HosseinShabani / react-native-modern-datepicker

A customizable calendar, time & month picker for React Native (including Persian Jalaali calendar & locale)
MIT License
577 stars 165 forks source link

onSelectedChange is being called multiple times on selecting a date its hard to add any side effect behaviour #139

Closed roneyyb closed 1 year ago

roneyyb commented 1 year ago

Describe the bug onSelectedChange is being called multiple times on selecting a date its hard to add any side effect behaviour. Even if date is already selected then also on selected change is being called.

To Reproduce Steps to reproduce the behavior: import moment from 'moment' import React, { useState } from 'react' import DatePicker from 'react-native-modern-datepicker'

export const CalendarModal = ({ isVisible, closeModal, onDayPress }) => { const firstTime = React.useRef(0) const handleConfirm = (date) => { console.log('date', date, firstTime.current)

if (date == selectedDate) {
  firstTime.current += 1
  return
}

setSelectedDate(date)
setTimeout(() => {
  // side effect call
}, 500)

}

React.useEffect(() => { if (isVisible) { firstTime.current = true } }, [isVisible])

const [selectedDate, setSelectedDate] = useState('')

console.log(selectedDate) return ( <DatePicker // current={selectedDate} selected={selectedDate} onSelectedChange={(date) => { handleConfirm(date) }} options={{ mainColor: '#30B700' }} mode="calendar" minuteInterval={30} style={{ borderRadius: 10 }} /> ) }

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

HacerBusraKILIC commented 6 months ago

Hello @roneyyb,

I have same issue. Can you solve this?