# action

```typescript
import { AsyncAction } from 'overmind'

export const getPosts: AsyncAction = async ({ state, actions, effects }) => {
  state.isLoadingPosts = true
  state.posts = await effects.api.getPosts()
  state.isLoadingPosts = false
}
```

An action is where you write the logic of the application. Every action receives at least one argument and that is the **context**. This is the signature of the context:

`{ state, actions, effects }`

This *injected* context allows Overmind to understand from where you are changing state and running effects. You can also use other actions defined in your application. Additionally with *injection* your actions become highly testable as it can easily be mocked.

State changes are restricted to these actions. That means if you try to change the state outside of an action you will get an error. The state changes are also scoped to the action. That means it does not matter if you perform the state change asynchronously, either by defining the action as an **async** function or for example use a **setTimeout**. You can change the state at any time within the action.

## Payload

When an action is called you can optionally pass it a payload. This payload is received as the second argument to the action.

```typescript
import { Action } from 'overmind'

export const setTitle: Action<string> = ({ state }, title) => {
  state.title = title
}
```

{% hint style="info" %}
There is only one argument, which means if you want to pass multiple values you have to do so with an object
{% endhint %}

## Typing

There are two different action types in Overmind, **Action** and **AsyncAction**. Both of them takes an Input param and an Output param where both of them default to **void**.

`Action<void, void>`

`AsyncAction<void, void>`.

The difference is that **AsyncAction** returns a Promise of the output, **Promise\<void>**. Basically whenever you use an **async** action or explicitly return a promise from an action you should use the **AsyncAction** type.


---

# 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://overmindjs.org/v23/api-1/action.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.
