Skip to content

Commit

Permalink
refactor(calendar input): use setter function instead of useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Jan 16, 2024
1 parent fdd1bd9 commit 49a5490
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions components/calendar/src/calendar-input/calendar-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,27 @@ export const CalendarInput = ({
} = {}) => {
const ref = useRef()
const [open, setOpen] = useState(false)
const [tempInputValue, setTempInputValue] = useState(date)
const [tempInputValue, _setTempInputValue] = useState(date)

useEffect(() => {
const isValidInputDate = validateInput(tempInputValue)
if (isValidInputDate && date !== tempInputValue) {
const [year, month, day] = tempInputValue.split('-')
const setTempInputValue = (nextTempValue) => {
_setTempInputValue(nextTempValue)
const isValidInputDate = validateInput(nextTempValue)

if (isValidInputDate) {
const [year, month, day] = nextTempValue.split('-')
const nextDate = Temporal.PlainDate.from({
calendar,
year,
month,
day,
})

onDateSelect({
calendarDate: nextDate,
calendarDateString: tempInputValue,
calendarDateString: nextTempValue,
})
}
}, [calendar, date, tempInputValue, onDateSelect])
}

const calendarProps = React.useMemo(() => {
const onDateSelectWrapper = (selectedDate) => {
Expand Down

0 comments on commit 49a5490

Please sign in to comment.