debug Date loop
parent
35386350c6
commit
f8cf7c2b69
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue