on ea25a45 help sign in
bridge/src/form/ValidationPauser.js
27 lines 959 B history raw
1import { useEffect } from 'react';
2import { useForm } from 'react-final-form';
4/**
5 * pauses validation when it becomes unmounted
6 *
7 * NOTE: this is useful because for some reason, final-form will
8 * re-run validation when a field is unregistered (even post submission !?),
9 * which react-final-form does on unmount. So when we redirect away from
10 * a page with a form on it, all of the validation is re-triggered.
11 *
12 * Normally, for boring sync-validation-only situations, this is ok, but for
13 * long-running validators like ours (deriving seeds, checking chain, etc)
14 * having them re-triggered when a form leaves the page is hilariously bad.
15 *
16 * So here we disable validation when unmounting, saving ourselves
17 * from the footgun.
18 *
19 * see: https://github.com/final-form/react-final-form/issues/408
20 */
21export default function ValidationPauser() {
22 const form = useForm();
24 useEffect(() => () => form.pauseValidation(), [form]);
26 return null;