fix(RooTips): Clear setTimeout in useEffect cleanup to prevent state updates on unmounted components (#4235)

fix: auto patch for RooTips_37
This commit is contained in:
kiwina 2025-06-05 04:49:55 +08:00 committed by GitHub
parent 15b37134c1
commit 815a0fb846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,15 +32,21 @@ const RooTips = ({ cycle = false }: RooTipsProps) => {
useEffect(() => {
if (!cycle) return
let timeoutId: NodeJS.Timeout | undefined = undefined
const intervalId = setInterval(() => {
setIsFading(true) // Start fade out
setTimeout(() => {
timeoutId = setTimeout(() => {
setCurrentTipIndex((prevIndex) => (prevIndex + 1) % tips.length)
setIsFading(false) // Start fade in
}, 1000) // Fade duration
}, 11000) // 10s display + 1s fade
return () => clearInterval(intervalId) // Cleanup on unmount
return () => {
clearInterval(intervalId)
if (timeoutId) {
clearTimeout(timeoutId)
}
}
}, [cycle])
const currentTip = tips[currentTipIndex]