https://github.com/hungtcs/react-axios
https://github.com/hungtcs/react-axios
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hungtcs/react-axios
- Owner: hungtcs
- Created: 2023-04-28T03:39:55.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-09T01:15:25.000Z (about 3 years ago)
- Last Synced: 2025-06-08T16:39:25.532Z (about 1 year ago)
- Language: TypeScript
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Axios
React Axios is a React library based on Axios that aims to provide better HTTP request handling
capabilities for React applications. The library provides an AxiosProvider component that makes
it easy to use Axios throughout your entire React application, and includes a useAxios hook
and some customizable interceptors.
## Installation
```shell
npm install @cicara/react-axios
```
## Usage
To use Axios in your React components, you need to provide an AxiosProvider component in your
application. In the AxiosProvider component, you can set the configuration for the Axios instance,
and add interceptors for custom handling.
```tsx
import { useEffect } from "react";
import { useAxios, AxiosProvider } from "@cicara/react-axios";
function TestAxios() {
const axios = useAxios();
useEffect(
() => {
const ac = new AbortController();
// GET request to `/base/url/test?_t=1682750920279`
axios.get("/test", { signal: ac.signal })
.catch((err) => {
console.error(err);
});
return () => {
ac.abort();
};
},
[axios],
);
return (
Axios Test
);
}
export default function App() {
return (
);
}
```