1.0.1 • Published 3 years ago

@ib-hooks/use-axios v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@ib-hooks/use-axios

React Hook to fetch or re-fetch api using axios easier.

Installation

yarn

yarn add @ib-hooks/use-axios

npm

npm i @ib-hooks/use-axios

Usage

import React from "react";
import useAxios from "@ib-hooks/use-axios";

function App() {
  const {
    response: { loading, data, error },
    refetch,
  } = useAxios({ url: API_URL });

  return (
    <div>
      <h1>{data && data.status}</h1>
      <h2>{error && error.message}</h2>
      <h3>{loading && "fetching..."}</h3>
      <button onClick={refetch}>Refetch API</button>
    </div>
  );
}

Arguments

ArgumentTypeDescriptionRequiredDefault value
optionsobjectReferenceyesundefined
axiosInstanceobjectYou can choose axios instance customly.nodefaultAxios

Return

Return valueTypeDescription
object(response, refetch)objectSee below
response(loading, data, error)objectResponse data of fetch api.
refetchfunctionThe refetch function executes when the user want to refetch api.