-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec4cc75
commit de73081
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as submitErrorsMutators } from './submitErrorsMutators' | ||
export { default as SubmitErrorsSpy } from './SubmitErrorsSpy' | ||
export { default as useResetSubmitErrors } from './useResetSubmitErrors' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
import { useForm } from 'react-final-form'; | ||
|
||
const useResetSubmitErrors = () => { | ||
const form = useForm(); | ||
const prevValues = useRef(form.getState().values); | ||
useEffect(() => { | ||
const unsubscribe = form.subscribe( | ||
({ values }) => { | ||
form.mutators.resetSubmitErrors({ | ||
current: values, | ||
prev: prevValues.current, | ||
}); | ||
|
||
prevValues.current = values; | ||
}, | ||
{ values: true } | ||
); | ||
return unsubscribe; | ||
}, [form]); | ||
}; | ||
|
||
export default useResetSubmitErrors; |