react-promise-suspense
React hook for resolving promises with Suspense support
Last updated 3 years ago by vigzmv .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-promise-suspense 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.3.4                                ...           latest (3 years ago)

7 Versions

  • 0.3.4                                ...           3 years ago
  • 0.3.3                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           7 years ago
  • 0.3.0                                ...           7 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 6
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |