# use-vc-axios

> React library to work with axios more convenient.

Latest version **1.0.2** (published 2022-03-11) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install use-vc-axios
pnpm add use-vc-axios
yarn add use-vc-axios
bun add use-vc-axios
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-03-11 |
| First published | 2022-03-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | VichetN |
| Maintainers | vichetn |
| Keywords | axios, useAxios |

## Links

- npm: https://www.npmjs.com/package/use-vc-axios
- npm.io page: https://npm.io/package/use-vc-axios

## Recent versions

- 1.0.2 (latest) — 2022-03-11
- 1.0.1 — 2022-03-11
- 1.0.0 — 2022-03-10

## README

# Introduction

React library to work with axios more convenient.

# Installation
You need to install Axios to support use-vc-axios<br/>
```npm install axios``` <br/>
And you can install use-vc-axios<br/>
```npm install use-vc-axios```

# Usage

Create `apiInstance.js` and export to call when using use-vc-axios
```js
    import axios from "axios";
    const instance = axios.create({
        baseURL: 'https://example.com/api',
        headers: {
            "authorization":'Bearer YWxhZGRpbjpvcGVuc2VzYW1l'
        }
    });
    export default instance;
```

React<br/>

Call api instance<br/>
```import instance from apiInstance.js```<br/>

Call library<br/>
```import { useVCAxios } from 'use-vc-axios'```<br/>
```import { useVCLazyAxios } from 'use-vc-axios'```<br/>

`useVCAxios example:`
```js
    import { useVCAxios } from 'use-vc-axios'
    import instance from 'apiInstance.js'
    const { data, loading, refetch } = useVCAxios({
            axiosInstance: instance,
            url: '/get/data',
            variables: {
                data:'test'
            },
            method:'POST'
    })
```

`useVCLazyAxios example:`
```js
    import { useVCLazyAxios } from 'use-vc-axios'
    import instance from 'apiInstance.js'
    const { data, loading, operation } = useVCLazyAxios({
        axiosInstance: instance,
        url: '/get/data',

        method:'POST'
    })
```

```js
    <button onClick={() => operation({variables:{data:'test'}})}>refetch</button>
```

# API
`useVCAxios:`<br/>
`axiosInstance:` api which created in apiInstance.js `axiosInstance: instance`, Required<br/>
`method:` String `GET | POST | PUT`, Default `GET`<br/>
`url:` String, `example: /get/data`, which after base URL that'd defined in `apiInstance.js`, Required<br/>
`variables:` Object, data which send to `url`, Not required<br/>

response:<br/>
`data:` Response data from backend<br/>
`loading:` Boolean, Status of requesting `true | false`<br/>
`error:` Error data if any problem is happening<br/>
`refetch:` Function, to excute your method again<br/>

useVCLaxyAxios:<br/>
`axiosInstance:` api which created in apiInstance.js `axiosInstance: instance`, Required<br/>
`method:` String `POST | PUT`, Default `POST`<br/>
`url:` String, `example: /post/data`, which after base URL that'd defined in `apiInstance.js`, Required<br/>

response:<br/>
`operation:` Function, to trigger and send `variables example: {data:'test'}` to your method<br/>
`data:` Response data from backend<br/>
`loading:` Boolean, Status of requesting `true | false`<br/>
`error:` Error data if any problem is happening<br/>

---
_Source: https://npm.io/package/use-vc-axios · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
