Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pinussilvestrus/use-spinner

Add a simple loading spinner to your async JS calls - built for the browser.
https://github.com/pinussilvestrus/use-spinner

async-await javascript loading-spinner

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# use-spinner

[![CI](https://github.com/pinussilvestrus/use-spinner/actions/workflows/CI.yml/badge.svg)](https://github.com/pinussilvestrus/use-spinner/actions/workflows/CI.yml) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/use-spinner?label=package%20size)](https://bundlephobia.com/result?p=use-spinner@latest)

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

## Installation

```sh
$ npm install --save use-spinner
```

## Usage

```js
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](./docs/screencast.gif)

## Options

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

```js
{
container: 'body'
}
```

* *container*: a selector or a DOM element that appends the loading spinner.

## License

MIT