1.0.0 • Published 3 years ago

@practical-react-hooks/use-axios v1.0.0

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

@practical-react-hooks/use-axios

React Hook to make HTTP requests with allowing to set configurations and customizations

Installation

yarn

yarn add @practical-react-hooks/use-axios

npm

npm i @practical-react-hooks/use-axios

Usage

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

const App = () => {
  return (
    const { loading, error, data, refetch } = useAxios({
      url: "API url"
    })
    <div className="App">
      <h1>{data && data.status}</h1>
      <h2>{loading && "Loading"}</h2>
      <button onClick={refetch}>Refetch</button>
    </div>
  );
};

Arguments

ArgumentTypeDescriptionRequired
optionsobjectsObject to make HTTP requestsyes
axiosInstanceobjectsTo set configurations and customizations of axiosno

Return

Return valueTypeDescription
loadingbooleanWhen loading is finished return flase or not true
errorstringLet know error message
dataobjectsObject from API request
refetchFunctionFunction to make reloading