> For the complete documentation index, see [llms.txt](https://react-use-api.gitbook.io/react-use-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://react-use-api.gitbook.io/react-use-api/api/useapi.md).

# useApi

### **Code**

```jsx
const [data, state, request] = useApi(config, options)
```

### **Types**

```typescript
const [data, state, request] = useApi(
  config: ReactUseApi.Config | string,
  opt?: ReactUseApi.Options | ReactUseApi.Options['handleData']
)
```

### Config

The config can be an [Axios Request Config](https://github.com/axios/axios#request-config) or a URL string.

### Options \[Optional]

| Name          | Type                                          | default | Description                                                                                                                                                                                                   |
| ------------- | --------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| handleData    | Function(data: any, state: ReactUseApi.State) |         | A callback function to deal with the data of the API's response. **IMPORTANT** Using any state setter in handleData is dangerous, which will cause the component re-rendering infinitely while SSR rendering. |
| dependencies  | Object                                        |         | The additional needed data using in handleData. `NOTE`: "dependencies" is supposed to immutable due to React's rendering policy.                                                                              |
| shouldRequest | Function                                      |         | A callback to decide whether useApi re-fetches the API when re-rendering. Returning true will trigger useApi to re-fetch. This option is helpful if you want to re-request an API when a route change occurs. |
| watch         | any\[]                                        | \[]     | An array of values that the effect depends on, this is the same as the second argument of useEffect.                                                                                                          |
