Improve useAsync code.
This commit is contained in:
parent
eee7998581
commit
9fadcfb1b2
1 changed files with 2 additions and 2 deletions
|
@ -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({
|
||||||
|
|
Loading…
Reference in a new issue