Skip to content

Commit

Permalink
Use useAsync again
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 23, 2023
1 parent 2ac9bd4 commit e914693
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ paths:
required: true
tags:
- forms
- form-definitions
security:
- tokenAuth: []
- cookieAuth: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit e914693

Please sign in to comment.