From f672cee3a034bed44a3e1fa2eec9e09864a50915 Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 29 Sep 2020 13:11:06 -0400 Subject: [PATCH 1/2] Reset error/result only after the next request has resolved to prevent render flicking --- awx/ui_next/src/util/useRequest.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/awx/ui_next/src/util/useRequest.js b/awx/ui_next/src/util/useRequest.js index 764297941a..c208aadfcb 100644 --- a/awx/ui_next/src/util/useRequest.js +++ b/awx/ui_next/src/util/useRequest.js @@ -38,18 +38,16 @@ export default function useRequest(makeRequest, initialValue) { request: useCallback( async (...args) => { setIsLoading(true); - if (isMounted.current) { - setResult(initialValue); - setError(null); - } try { const response = await makeRequest(...args); if (isMounted.current) { setResult(response); + setError(null); } } catch (err) { if (isMounted.current) { setError(err); + setResult(initialValue); } } finally { if (isMounted.current) { @@ -57,7 +55,6 @@ export default function useRequest(makeRequest, initialValue) { } } }, - /* eslint-disable-next-line react-hooks/exhaustive-deps */ [makeRequest] ), setValue: setResult, From e13b16bf1c9b9c5c95c3bc88889e2e24580f881f Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 29 Sep 2020 15:42:11 -0400 Subject: [PATCH 2/2] Add erroneously removed exhaustive dep comment --- awx/ui_next/src/util/useRequest.js | 1 + 1 file changed, 1 insertion(+) diff --git a/awx/ui_next/src/util/useRequest.js b/awx/ui_next/src/util/useRequest.js index c208aadfcb..8dc7e9a282 100644 --- a/awx/ui_next/src/util/useRequest.js +++ b/awx/ui_next/src/util/useRequest.js @@ -55,6 +55,7 @@ export default function useRequest(makeRequest, initialValue) { } } }, + /* eslint-disable-next-line react-hooks/exhaustive-deps */ [makeRequest] ), setValue: setResult,