fix: scroll to top on survey slide change via useEffect
requestAnimationFrame was still too early. Use a useEffect on currentSlide so the scroll fires after React commits the new slide to the DOM. Skips initial render to avoid scroll on load. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -188,11 +188,18 @@ export default function SurveyPage() {
|
||||
|
||||
const goSlide = (idx: number) => {
|
||||
setCurrentSlide(idx)
|
||||
requestAnimationFrame(() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
})
|
||||
}
|
||||
|
||||
// Scroll to top whenever the active slide changes
|
||||
const isFirstRender = useRef(true)
|
||||
useEffect(() => {
|
||||
if (isFirstRender.current) {
|
||||
isFirstRender.current = false
|
||||
return
|
||||
}
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}, [currentSlide])
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSubmitting(true)
|
||||
setSubmitError('')
|
||||
|
||||
Reference in New Issue
Block a user