From 9fadcfb1b25dea1fe4c30a11f7b6d1e77acbfeb5 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sun, 14 Jul 2024 10:54:14 +0200 Subject: [PATCH] Improve useAsync code. --- src/Async.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Async.tsx b/src/Async.tsx index 3c35729..d7cc11a 100644 --- a/src/Async.tsx +++ b/src/Async.tsx @@ -1,4 +1,4 @@ -import React, {useMemo, useState} from "react"; +import React, {useEffect, useState} from "react"; /** * Asynchronous data state. @@ -59,7 +59,7 @@ export function useAsync(promise: Promise|PromiseFn, deps: any[] = []): }; // Reconfigure the promise when any deps have changed. - useMemo(() => { + useEffect(() => { (promise as Promise).then((result) => { // When there is a result, disable pending state and set retrieved data, without error. updateState({