use-axios-loader
v1.1.0
Published
A tiny react hook to add a loader to all axios instances
Downloads
105
Maintainers
Readme
use-axios-loader
use-axios-loader
is a tiny React Hook, designed to easily add a loader to all your axios instances.
⚙️ Installation
npm install --save use-axios-loader
or
yarn add use-axios-loader
🚀 Usage
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.
License
MIT © olivier1208