debug Date loop

pull/2827/head
Jérémy Rialland 2023-09-27 17:19:02 +02:00 committed by Jérémy Rialland
parent 35386350c6
commit f8cf7c2b69
2 changed files with 15 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { lazy, Suspense, useCallback } from 'react'
import { lazy, Suspense, useCallback, useMemo } from 'react'
import { styled } from 'styled-components'
import { InputProps } from '@/components/conversation/RuleInput'
@ -43,7 +43,7 @@ export default function DateInput({
[onChange]
)
const dateValue = convertDate(value)
const dateValue = useMemo(() => new Date(convertDate(value) ?? NaN), [value])
return (
<div className="step input">
@ -68,9 +68,9 @@ export default function DateInput({
<Suspense fallback={<DateFieldFallback />}>
<DateField
defaultSelected={
(missing && hideDefaultValue) || !dateValue
(missing && hideDefaultValue) || !isNaN(+dateValue)
? undefined
: new Date(dateValue)
: dateValue
}
isRequired={required}
onChange={handleDateChange}

View File

@ -135,13 +135,23 @@ export default function DateField(props: DateFieldProps) {
}
}, [])
useEffect(() => console.log('DateField onChange:', onChange), [onChange])
useEffect(
() => console.log('DateField defaultSelected:', defaultSelected),
[defaultSelected]
)
useEffect(
() => console.log('DateField refs.reference:', refs.reference),
[refs.reference]
)
const oldDefaultSelected = useRef<Date | undefined>(defaultSelected)
useEffect(() => {
if (
typeof defaultSelected !== 'undefined' &&
oldDefaultSelected.current?.getTime() !== defaultSelected.getTime()
) {
console.log('DateField useEffect loop ?')
console.log('DateField useEffect loop ?', defaultSelected)
handleDaySelect(defaultSelected)
oldDefaultSelected.current = defaultSelected
}