# Usage

Use `<Await />` component to load your data in your components. You can take advantage of [Yielded Components](/ember-await/api/yielded-components.md), like `Pending`, `Fulfilled` or `Rejected` to define your UI based on promise state, example:

```
  <Await @promise={{this.fetchPosts}} as |await|>
    <await.Pending>
      Loading posts...
    </await.Pending>

    <await.Fulfilled as |posts|>
      {{#each posts as |post|}}
        {{post.title}}
      {{/each}}
    </await.Fulfilled>

    <await.Rejected>
      Something went wrong :(
    </await.Rejected>
  </Await>
```

You can also control the state yourself using [Yielded properties](/ember-await/api/yielded-properties.md), where you can access `isPending`, `isRejected` etc...

```
  <Await @promise={{this.fetchPosts}} as |await|>
    <div class={{if await.isPending "loading"}}>
      Hey there :) This text will spin when content is loading.
    </div>
  </Await>
```

Your `@promise` can be anything. A promise, function which returns promise, a task (from ember-concurrency) or normal string. Sky is the limit.

You can also load the promise on demand using `@defer`:

```
  <Await @defer={{this.fetchPosts}} as |await|>
    <button {{on "click" await.run}}>Load posts</button>

    <await.Fulfilled as |posts|>
      {{#each posts as |post|}}
        {{post.title}}
      {{/each}}
    </await.Fulfilled>
  </Await>
```

For more useful patterns in Ember Await check out the rest of the documentation and visit [React Async](https://react-async.com) for reference.

**More Guides are coming soon!**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://exelord.gitbook.io/ember-await/getting-started/usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
