Improve useAsync code.

This commit is contained in:
Madeorsk 2024-07-14 10:54:14 +02:00
parent eee7998581
commit 9fadcfb1b2
Signed by: Madeorsk
SSH key fingerprint: SHA256:J9G0ofIOLKf7kyS2IfrMqtMaPdfsk1W02+oGueZzDDU

View file

@ -1,4 +1,4 @@
import React, {useMemo, useState} from "react"; import React, {useEffect, useState} from "react";
/** /**
* Asynchronous data state. * Asynchronous data state.
@ -59,7 +59,7 @@ export function useAsync<T>(promise: Promise<T>|PromiseFn<T>, deps: any[] = []):
}; };
// Reconfigure the promise when any deps have changed. // Reconfigure the promise when any deps have changed.
useMemo(() => { useEffect(() => {
(promise as Promise<T>).then((result) => { (promise as Promise<T>).then((result) => {
// When there is a result, disable pending state and set retrieved data, without error. // When there is a result, disable pending state and set retrieved data, without error.
updateState({ updateState({