1.0.2 • Published 3 years ago

@nooks-practice/use-axios v1.0.2

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

@nooks-practice/use-axios

React Hook to use Axios

Installation

yarn

yarn add @nooks-practice/use-axios

npm

npm i @nooks-practice/use-axios

Usage

import React from "react";
import useAxios from "@nooks-practice/use-axios";

function App() {
  const { loading, data, error, refetch } = useAxios({
    url: "https://yts-proxy.now.sh/list_movies.json"
  });

  return (
    <div className="App">
      <div className="content">
        <h1>{!loading && data && data.status}</h1>
        <h2>{loading && "loading"}</h2>
        <div>{error && error.message}</div>
        <button onClick={refetch}>Refetch</button>
      </div>
    </div>
  );
};

Arguments

ArgumentTypeDescriptionRequired
optionsobjectConfig options for Axios requestsyes
axiosInstanceAxiosInstanceCustomized axios instance (or default axios instance)no

Return

Return valueTypeDescriptionDefault value
loadingbooleanA boolean representing if response is loading or nottrue
errorobjectAxios errornull
dataobjectAxios response datanull
refetchfunctionFunction to refetch data