use-spinner

0.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i use-spinner

Weekly Downloads

5

Version

0.2.0

License

MIT

Unpacked Size

5.9 kB

Total Files

7

Last publish

Collaborators

  • pinussilvestrus