1.0.0 • Published 4 years ago

@ej-hooks/use-axios v1.0.0

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

@ej-hooks/use-axios

React Hook to make HTTPRequest using axios.

Installation

yarn

yarn add @ej-hooks/use-axios

npm

npm i @ej-hooks/use-axios

Usage

import React from 'react';
import useAxios from '@ej-hooks/use-axios';
function App() {
  const { loading, data, refetch } = useAxios({
    url: 'https://yts.mx/api/v2/list_movies.json',
  });
  return (
      <h1>{data && data.status}</h1>
      <h2>{loading && "Loading"}</h2>
      <button onClick={refetch}>Refetch</button>
  );
}

Arguments

ArgumentTypeDescriptionRequired
optsobjectAn object containing the url to send request toyes
axiosInstanceinstanceAn Instance to make request withno

Return

Return valueTypeDescriptionDefault value
stateobjectAn object containing the loading, error and data{ loading: true, error: null, data: null }
refetchfunctionFunction to execute useEffect again