1.0.0 • Published 4 years ago

@sullivan/use-async v1.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
4 years ago

npm version npm license

@sullivan/use-async

Hook friendly asynchronous operations for React 16.8+.

Installation

npm install --save @sullivan/use-async

or

yarn add @sullivan/use-async

Usage

import React from 'react';
import { useAsync } from '@sullivan/use-async';

const Example = (props) => {
  const { loading, data, error, dispatch } = useAsync(fetch);
  
  return (
    <div onClick={() => dispatch('some_url')}>
      <h1>{loading ? 'Loading' : 'Done'}</h1>
    </div>
  );
};

Options

useAsync(fn, options?) => Response

OptionDescriptionType
debounceMilliseconds to perform a debounce, ignores if unsetnumber
memoizeIf memoization should be doneboolean

Response

FieldDescription
loadingIf the async call is occuring
errorAny error that was thrown
dataThe success result of the async call
dispatchHow to invoke the async function

Changelog

0.2.0

  • Removed withAsync HOC
  • Added options for debounce and memoization
1.0.0

4 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago