From e914693e8b5e8b93cffd58d554d8f708f57134c7 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:00:15 +0200 Subject: [PATCH] Use `useAsync` again --- src/openapi.yaml | 1 + .../admin/form_design/form-creation-form.js | 22 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/openapi.yaml b/src/openapi.yaml index ef9ad80413..1d045b7eed 100644 --- a/src/openapi.yaml +++ b/src/openapi.yaml @@ -1133,6 +1133,7 @@ paths: required: true tags: - forms + - form-definitions security: - tokenAuth: [] - cookieAuth: [] diff --git a/src/openforms/js/components/admin/form_design/form-creation-form.js b/src/openforms/js/components/admin/form_design/form-creation-form.js index bca823ec72..554f77ca3b 100644 --- a/src/openforms/js/components/admin/form_design/form-creation-form.js +++ b/src/openforms/js/components/admin/form_design/form-creation-form.js @@ -997,20 +997,16 @@ const FormCreationForm = ({formUuid, formUrl, formHistoryUrl}) => { }); }, []); - // Using useEffect to avoid race conditions when mutating state: - useEffect(() => { + useAsync(async () => { + // Waiting for the last dispatch to be done to avoid state race conditions. if (!loading) { - const fetchData = async () => { - const reusableFormDefinitions = await loadFromBackend([ - {endpoint: FORM_DEFINITIONS_ENDPOINT, query: {is_reusable: true}}, - ]); - dispatch({ - type: 'REUSABLE_FORM_DEFINITIONS_LOADED', - payload: reusableFormDefinitions[0], - }); - }; - - fetchData(); + const reusableFormDefinitions = await loadFromBackend([ + {endpoint: FORM_DEFINITIONS_ENDPOINT, query: {is_reusable: true}}, + ]); + dispatch({ + type: 'REUSABLE_FORM_DEFINITIONS_LOADED', + payload: reusableFormDefinitions[0], + }); } }, [loading]);