0.2.0 • Published 3 years ago

use-spinner v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

use-spinner

CI npm bundle size

Add a simple loading spinner to your async JS calls - built for the browser.

Installation

$ npm install --save use-spinner

Usage

import useSpinner from 'use-spinner';

import 'use-spinner/assets/use-spinner.css';

const fn = async () => {
  await new Promise(resolve => setTimeout(() => {
    console.log('done.');
    resolve();
  }, 2000));
};

// wrap your asynchronous function
const spinnedFn = useSpinner(fn, {
  container: 'body'
});

// execute with a loading spinner
await spinnedFn();

Screencast

Options

The API accepts a second argument configuring the wrapped function. This defaults to:

{
  container: 'body'
}
  • container: a selector or a DOM element that appends the loading spinner.

License

MIT