use-axios-loader

1.0.11 • Public • Published

use-axios-loader

use-axios-loader is a tiny React Hook, designed to easily add a loader to all your axios instances.

NPM JavaScript Style Guide

⚙️ 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 in the ignoredUrls variable, won't trigger the loader.

License

MIT © olivier1208


Package Sidebar

Install

npm i use-axios-loader

Weekly Downloads

11

Version

1.0.11

License

MIT

Unpacked Size

22.1 kB

Total Files

14

Last publish

Collaborators

  • scorpioliv