rps
react-promise-suspense
npm i react-promise-suspense
rps

react-promise-suspense

A React hook for resolving promises with Suspense support. <1kb bundle.

by Vignesh M

0.3.3 (see all)License:MITTypeScript:Not Found
npm i react-promise-suspense
Readme

usePromise

React hook for resolving promises with Suspense support.

Inspired by fetch-suspense, but this one is not limited to fetch, usePromise works with any Promise.

version minified size minzipped size downloads

Install

  • npm install react-promise-suspense --save

Example

import usePromise from 'react-promise-suspense';

const fetchJson = input => fetch(input).then(res => console.log(res) || res.json());

const MyFetchingComponent = () => {
  // usePromise(Promise, [inputs,],)
  const data = usePromise(fetchJson, [
    'https://pokeapi.co/api/v2/pokemon/ditto/',
    { method: 'GET' },
  ]);

  return <pre>{JSON.stringify(data, null, 2)}</pre>;
};

const App = () => {
  return (
    <Suspense fallback="Loading...">
      <MyFetchingComponent />
    </Suspense>
  );
};

Downloads/wk

9.3K

GitHub Stars

123

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

6

OPEN PRs

1
VersionTagPublished
0.3.3
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate