> For the complete documentation index, see [llms.txt](/llms.txt).
> The full corpus is at [llms-full.txt](/llms-full.txt).

# effect

> **effect**(`effect`): `object`

Defined in: behavior.types.action.ts:203

Performs a side effect.

Use `effect` for logging, analytics, async operations, or other side effects.

**Note:** Using `effect` alone (without `forward`) will stop event
propagation. To perform a side effect while allowing the default Behavior
to continue, combine `effect` with `forward`.

The effect callback receives a `send` function that can be used to send
events back to the editor asynchronously.

:::caution[Beta]
This API should not be used in production and may be trimmed from a public release.
:::

## Parameters

### effect

(`payload`) => `void`

## Returns

`object`

### effect()

> **effect**: (`payload`) => `void`

#### Parameters

##### payload

###### send

(`event`) => `void`

Send a Behavior Event back into the Editor.

**Example**

```ts
defineBehavior({
  on: '...',
  actions: [
    () => [
      effect(({send}) => {
        doSomethingAsync()
          .then(() => {
            send({
              type: '...',
            })
          })
      })
    ],
  ],
})
```

#### Returns

`void`

### type

> **type**: `"effect"`

## Example

```ts
// Log events while preserving default Behavior
defineBehavior({
  on: 'insert.text',
  actions: [({event}) => [effect(() => console.log(event)), forward(event)]],
})

// Effect alone stops propagation (native event is cancelled)
defineBehavior({
  on: 'keyboard.keydown',
  actions: [() => [effect(() => console.log('key pressed'))]],
})

// Async effect that sends an event later
defineBehavior({
  on: 'custom.save',
  actions: [
    () => [
      effect(async ({send}) => {
        await saveDocument()
        send({type: 'custom.saved'})
      }),
    ],
  ],
})
```