Axios wrapper for react
npm install @crushers-lab/axios-hooks[license]:https://img.shields.io/npm/l/@crushers-lab/axios-hooks
[version]:https://img.shields.io/npm/v/@crushers-lab/axios-hooks
[npm-url]: https://www.npmjs.com/package/@crushers-lab/axios-hooks
[size]: https://packagephobia.now.sh/badge?p=@crushers-lab/axios-hooks
[size-url]: https://packagephobia.now.sh/result?p=@crushers-lab/axios-hooks
``bash`
npm i @crushers-lab/axios-hooks`
ORbash`
yarn add @crushers-lab/axios-hooks
bash
npm i react axios prop-types
`
OR
`bash
yarn add react axios prop-types
`Usage
$3
`jsx
import { AxiosProvider } from "@crushers-lab/axios-hooks";
import Axios from 'axios';const connector = Axios.create();
function App() {
return (
...
)
}
`$3
`jsx
import {useGet} from '@crushers-lab/axios-hooks';
function ExampleComponent() {
const [data, error, isLoading, status, reload ] = useGet('/user');
if(isLoading) {
return Loading...;
}
if(error) {
return {error};
}
return {data}
}
`
$3
`jsx
import {usePostCallback} from '@crushers-lab/axios-hooks';
function MyComponent() {
const postData = usePostCallback('/user');
const onSubmit = ()=>{
const data = {};
postData({data}).then(console.log).catch(console.error);
// Business logic
}
return
}
`$3
`jsx
import {AxiosGet, useAxiosData, useAxiosError} from "@crushers-lab/axios-hooks";
function MyComponent() {
return (
Loading... function RenderUser() {
const user = useAxiosData();
const error = useAxiosError();
if(error) {
return