Nobody Publish Monsters

    react-promise-suspense
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.3 • Public • Published

    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>
      );
    };

    Install

    npm i react-promise-suspense

    DownloadsWeekly Downloads

    5,772

    Version

    0.3.3

    License

    MIT

    Unpacked Size

    6.45 kB

    Total Files

    5

    Last publish

    Collaborators

    • vigzmv