React Hook to execute a function when axios
npm install @loyhooks/use-axiosReact Hook to execute a function when axios
#### yarn
yarn add @loyhooks/use-axios
#### npm
npm i @loyhooks/use-axios
``js
import React from "react";
import useBeforeLeave from "@loyhooks/use-axios";
const App = () => {
const { loading, data, error, refetch } = useAxios({
url: "https://yts.am/api/v2/list_movies.json"
});
console.log(
Loading:${loading}\nError:${error}\nData:${JSON.stringify(data)}
);
return (
{data && data.status}
{loading && "Loading"}
);
};
``
| Argument | Type | Description | Required |
| ------------- | -------- | -------------------------------------------------------- | -------- |
| onBeforeLeave | function | Function to be called when the mouse leaves the document | yes |