Skip to content

Commit

Permalink
Fix use-revert-on-cancel (#9286)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers committed Jul 29, 2024
1 parent 266397e commit 4a80ac2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/mobile/src/screens/form-screen/useRevertOnCancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useFormikContext } from 'formik'
import { useNavigation } from 'app/hooks/useNavigation'

export const useRevertOnCancel = (active?: boolean) => {
const { values, setValues } = useFormikContext()
const { values, setValues } = useFormikContext() ?? {}
const navigation = useNavigation()

// eslint-disable-next-line react-hooks/exhaustive-deps
const initialValues = useMemo(() => values, [])

useEffect(() => {
if (!active) return
if (!active || !initialValues) return
const listener = navigation.addListener('beforeRemove', ({ data }) => {
if (data.action.type === 'POP') {
setValues(initialValues)
Expand Down

0 comments on commit 4a80ac2

Please sign in to comment.