From f672cee3a034bed44a3e1fa2eec9e09864a50915 Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 29 Sep 2020 13:11:06 -0400 Subject: [PATCH] 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,