From 56dee29a37aadc41da9cbedf983cf24e55d2a20b Mon Sep 17 00:00:00 2001 From: David Heidrich Date: Wed, 27 Nov 2019 11:52:43 +0100 Subject: [PATCH] Use form.getState() directly instead of using subscriptions. --- src/decorator.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/decorator.js b/src/decorator.js index e6e1887..429b32e 100644 --- a/src/decorator.js +++ b/src/decorator.js @@ -25,18 +25,9 @@ const createDecorator = ( // Save original submit function const originalSubmit = form.submit - // Subscribe to errors, and keep a local copy of them - let state: { errors?: Object, submitErrors?: Object } = {} - const unsubscribe = form.subscribe( - nextState => { - state = nextState - }, - { errors: true, submitErrors: true } - ) - // What to do after submit const afterSubmit = () => { - const { errors, submitErrors } = state + const { errors, submitErrors } = form.getState() if (errors && Object.keys(errors).length) { focusOnFirstError(errors) } else if (submitErrors && Object.keys(submitErrors).length) { @@ -58,7 +49,6 @@ const createDecorator = ( } return () => { - unsubscribe() form.submit = originalSubmit } }