@ej-hooks/use-axios
v1.0.0
Published
React Hook to make HTTPRequest using axios.
Downloads
1
Maintainers
Readme
@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
| Argument | Type | Description | Required | | ------------- | -------- | ----------------------------------------------- | -------- | | opts | object | An object containing the url to send request to | yes | | axiosInstance | instance | An Instance to make request with | no |
Return
| Return value | Type | Description | Default value | | ------------ | -------- | ------------------------------------------------ | ------------------------------------------ | | state | object | An object containing the loading, error and data | { loading: true, error: null, data: null } | | refetch | function | Function to execute useEffect again | |