Skip to content

Commit

Permalink
fix: dont reset when submit is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Oct 11, 2024
1 parent aae4623 commit 2f26eb8
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function TurnstileField({
}) {
const ref = useRef<TurnstileInstance | null>(null);
const { setValue, setError } = window.givewp.form.hooks.useFormContext();
const { submitCount, errors } = window.givewp.form.hooks.useFormState();
const { submitCount, errors, isSubmitSuccessful } = window.givewp.form.hooks.useFormState();
const fieldName = inputProps.name;
const setFormError = useCallback(() =>
setError('FORM_ERROR', {
Expand All @@ -49,8 +49,10 @@ export default function TurnstileField({
}, [fieldError]);

useEffect(() => {
ref.current?.reset();
}, [submitCount]);
if (!isSubmitSuccessful) {
ref.current?.reset();
}
}, [submitCount, isSubmitSuccessful]);

return (
<>
Expand Down

0 comments on commit 2f26eb8

Please sign in to comment.