@sullivan/use-async

    1.0.0 • Public • Published

    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

    Option Description Type
    debounce Milliseconds to perform a debounce, ignores if unset number
    memoize If memoization should be done boolean

    Response

    Field Description
    loading If the async call is occuring
    error Any error that was thrown
    data The success result of the async call
    dispatch How to invoke the async function

    Changelog

    0.2.0

    • Removed withAsync HOC
    • Added options for debounce and memoization

    Install

    npm i @sullivan/use-async

    DownloadsWeekly Downloads

    4

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    9.79 kB

    Total Files

    8

    Last publish

    Collaborators

    • icarus-sullivan