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

# useAsyncState

#### 基础用法

```html
<template>
  <div v-for="item in data" :key="item">
    {{ item }}
  </div>
  {{ loading ? "true" : "false" }}
  <button @click="() => {
    run();
  }">run</button>
</template>

<script lang="ts" setup>
import { useAsyncState } from "hooks-vue3";

const promise = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('setTimeout模拟请求');
      resolve([1, 2, 3]);
    }, 300);
  });
};
const { data, loading, run } = useAsyncState(() => promise(), {
  manual: true,
});
</script>
```

### API

```typescript
const { data, loading, run } = useAsyncState(() => promise(), {
  manual: true,
});
```

### 参数TS类型

```typescript
import type { Ref } from 'vue';

function useBoolean (
  defaultBoolean = false,
): [state: Readonly<Ref<boolean>>, setTrue: () => void, setFalse: () => void] 
```
