use-axios-loader
is a tiny React Hook, designed to easily add a loader to all your axios instances.
npm install --save use-axios-loader
or
yarn add use-axios-loader
import React, { Component } from 'react'
import axiosInstance from 'axios'
import { useAxiosLoader } from 'use-axios-loader'
const MyComponent = () => {
// Pass the axios instance to the hook
// Allows you tu customize easily your instance
const [loading] = useAxiosLoader(axiosInstance)
return (
<>
{loading
? <img src="path/to/loader"/>
: <div>My data</div>
}
</>
)
}
👉 You may also pass an array of URLs to ignore. This is the second parameter accepted by this hook.
const ignoredUrls = ['https://myignoredurl.com', 'anotherignored.co']
const [loading] = useAxiosLoader(axiosInstance, ignoredUrls)
All urls passed to ignoredUrls
variable, won't trigger the loader.
MIT © olivier1208