mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Reset error/result only after the next request has resolved to prevent render flicking
This commit is contained in:
parent
2019f808b9
commit
f672cee3a0
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user