vigzmv / react-promise-suspense

A React hook for resolving promises with Suspense support. <1kb bundle.
https://npmjs.com/package/react-promise-suspense
MIT License
162 stars 9 forks source link
hacktoberfest hooks promise react suspense

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

Example

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

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

return

{JSON.stringify(data, null, 2)}
; };

const App = () => { return (

); };