Skip to content

Commit 453e634

Browse files
author
Peter Bengtsson
authored
reset survey after route navigation (#22488)
Part of #1115
1 parent 596207f commit 453e634

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

components/page-footer/Survey.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useState, useRef } from 'react'
1+
import { useState, useRef, useEffect } from 'react'
22
import cx from 'classnames'
3+
import { useRouter } from 'next/router'
34
import { ThumbsdownIcon, ThumbsupIcon } from '@primer/octicons-react'
45
import { useTranslation } from 'components/hooks/useTranslation'
56
import { Link } from 'components/Link'
@@ -13,10 +14,18 @@ enum ViewState {
1314
}
1415

1516
export const Survey = () => {
17+
const { asPath } = useRouter()
1618
const { t } = useTranslation('survey')
1719
const [state, setState] = useState<ViewState>(ViewState.START)
1820
const formRef = useRef<HTMLFormElement>(null)
1921

22+
useEffect(() => {
23+
// Always reset the form if navigating to a new page because what
24+
// you might have said or started to say belongs exclusively to
25+
// to the page you started on.
26+
setState(ViewState.START)
27+
}, [asPath])
28+
2029
function vote(state: ViewState) {
2130
return () => {
2231
trackEvent(getFormData())

0 commit comments

Comments
 (0)