@aslan-hooks/use-promise
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

use-promise

A React Hook that takes a promise which will be executed as an effect, with optional watchers

Installation Instructions

yarn add @aslan-hooks/use-promise

or

npm i --save @aslan-hooks/use-promise

Usage Instructions

import React from "react";

import usePromise from "@aslan-hooks/use-promise";

const fakeAPICall = () =>
  new Promise(resolve => {
    setTimeout(() => resolve("Text"), 1000);
  });

const Component = () => {
  const [loading, result, error, refresh] = usePromise(fakeAPICall);

  return <div>{loading ? "Loading..." : `The result is ${result}`}</div>;
};

Readme

Keywords

none

Package Sidebar

Install

npm i @aslan-hooks/use-promise

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

119 kB

Total Files

7

Last publish

Collaborators

  • deniztetik