Merge pull request #8267 from mabashian/8252-jt-tabs-reload

Reset error/result only after the next request has resolved to prevent render flickering

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-09-30 12:24:08 +00:00
committed by GitHub

View File

@@ -38,18 +38,16 @@ export default function useRequest(makeRequest, initialValue) {
request: useCallback( request: useCallback(
async (...args) => { async (...args) => {
setIsLoading(true); setIsLoading(true);
if (isMounted.current) {
setResult(initialValue);
setError(null);
}
try { try {
const response = await makeRequest(...args); const response = await makeRequest(...args);
if (isMounted.current) { if (isMounted.current) {
setResult(response); setResult(response);
setError(null);
} }
} catch (err) { } catch (err) {
if (isMounted.current) { if (isMounted.current) {
setError(err); setError(err);
setResult(initialValue);
} }
} finally { } finally {
if (isMounted.current) { if (isMounted.current) {