@feca-hooks/use-axios

1.0.1 • Public • Published

@feca-hooks/use-axios

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


How to Install

yarn

yarn add @feca-hooks/use-axios

npm

npm i @feca-hooks/use-axios


Usage

Code

import React from "react";
import useAxios from "@feca-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

Argument Type Description Required Default value
options object Reference yes undefined
axiosInstance object You can choose axios instance customly. no defaultAxios

Return

Return value Type Description
object(response, refetch) object See below
response(loading, data, error) object Response data of fetch api.
refetch function The refetch function executes when the user want to refetch api.

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @feca-hooks/use-axios

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.36 kB

    Total Files

    4

    Last publish

    Collaborators

    • pshtony1