use-spinner
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();
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