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

3.1.15 • Public • Published

Networking Hooks

CircleCI Coverage Status npm downloads bundle size npm version PRs Welcome

Composable hooks for networking data

useCancelling()

Aborts inflight request if the parameters change.

const data = useSuspense(useCancelling(MyEndpoint, { filter }), { filter });

useDebounce()

Delays updating the parameters by debouncing. Useful to avoid spamming network requests when parameters might change quickly (like a typeahead field).

const debouncedFilter = useDebounce(filter, 200);
const data = useSuspense(SearchList, { filter: debouncedFilter });

useLoading()

Helps track loading state of imperative async functions.

function Button({ onClick, children, ...props }) {
  const [clickHandler, loading, error] = useLoading(onClick);
  return (
    <button onClick={clickHandler} {...props}>
      {loading ? 'Loading...' : children}
    </button>
  );
}

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @rest-hooks/hooks

    Weekly Downloads

    880

    Version

    3.1.15

    License

    Apache-2.0

    Unpacked Size

    14.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • ntucker
    • ljharb