Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/pinussilvestrus/use-spinner
- Owner: pinussilvestrus
- License: mit
- Created: 2021-04-02T17:19:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-14T01:28:01.000Z (2 months ago)
- Last Synced: 2024-10-15T12:51:54.976Z (2 months ago)
- Topics: async-await, javascript, loading-spinner
- Language: JavaScript
- Homepage:
- Size: 270 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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