use-promise
The usePromise hook consumes an asynchronous function is ideal for using fetch or other asynchronous tasks.

Module

1
import { usePromise } from "@atomico/hooks/use-promise";
Copied!

Syntax

1
const [result, status] = usePromise(
2
asyncFunction,
3
runFunction,
4
optionalArguments
5
);
Copied!
Where :
  • result: Retorno de la promesa
  • status: Estado de la promesa:
    • "": Without executing.
    • "pending": In action.
    • "fulfilled": Successfully executed.
    • "rejected": Executed with error.
  • asyncFunction: asynchronous function.
  • runFunction: Booleano, if true it will execute the promise and define the status.
  • optionalArguments: Optional any[], allows to regenerate the promise through arguments.

Example

WebComponents.dev
WebComponents.dev
Copy link
Edit on GitHub