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

# defineBehavior

> **defineBehavior**\<`TPayload`, `TBehaviorEventType`, `TGuardResponse`\>(`behavior`): [`Behavior`](/api/behaviors/type-aliases/behavior/)

Defined in: behavior.types.behavior.ts:56

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

## Type Parameters

### TPayload

`TPayload` *extends* `Record`\<`string`, `unknown`\>

### TBehaviorEventType

`TBehaviorEventType` *extends* `` `custom.${string}` `` \| `"*"` \| `"annotation.add"` \| `"annotation.remove"` \| `"block.set"` \| `"block.unset"` \| `"child.set"` \| `"child.unset"` \| `"decorator.add"` \| `"decorator.remove"` \| `"delete"` \| `"history.redo"` \| `"history.undo"` \| `"insert"` \| `"insert.block"` \| `"insert.child"` \| `"insert.text"` \| `"move.backward"` \| `"move.forward"` \| `"remove.text"` \| `"select"` \| `"set"` \| `"unset"` \| `"annotation.set"` \| `"annotation.toggle"` \| `"decorator.toggle"` \| `"delete.backward"` \| `"delete.block"` \| `"delete.child"` \| `"delete.forward"` \| `"delete.text"` \| `"deserialize"` \| `"deserialize.data"` \| `"deserialization.success"` \| `"deserialization.failure"` \| `"insert.blocks"` \| `"insert.break"` \| `"insert.inline object"` \| `"insert.soft break"` \| `"insert.span"` \| `"list item.add"` \| `"list item.remove"` \| `"list item.toggle"` \| `"move.block"` \| `"move.block down"` \| `"move.block up"` \| `"select.block"` \| `"select.previous block"` \| `"select.next block"` \| `"serialize"` \| `"serialize.data"` \| `"serialization.success"` \| `"serialization.failure"` \| `"split"` \| `"style.add"` \| `"style.remove"` \| `"style.toggle"` \| `"clipboard.copy"` \| `"clipboard.cut"` \| `"clipboard.paste"` \| `"drag.dragstart"` \| `"drag.drag"` \| `"drag.dragend"` \| `"drag.dragenter"` \| `"drag.dragover"` \| `"drag.dragleave"` \| `"drag.drop"` \| `"input.*"` \| `"keyboard.keydown"` \| `"keyboard.keyup"` \| `"mouse.click"` \| `"delete.*"` \| `"insert.*"` \| `"select.*"` \| `"set.*"` \| `"unset.*"` \| `"deserialize.*"` \| `"serialize.*"` \| `"split.*"` \| `"annotation.*"` \| `"remove.*"` \| `"block.*"` \| `"child.*"` \| `"decorator.*"` \| `"history.*"` \| `"move.*"` \| `"deserialization.*"` \| `"list item.*"` \| `"serialization.*"` \| `"style.*"` \| `"clipboard.*"` \| `"drag.*"` \| `"keyboard.*"` \| `"mouse.*"` = `` `custom.${string}` ``

### TGuardResponse

`TGuardResponse` = `true`

## Parameters

### behavior

[`Behavior`](/api/behaviors/type-aliases/behavior/)\<`TBehaviorEventType`, `TGuardResponse`, `ResolveBehaviorEvent`\<`TBehaviorEventType`, `TPayload`\>\>

## Returns

[`Behavior`](/api/behaviors/type-aliases/behavior/)

## Example

```tsx
const noLowerCaseA = defineBehavior({
  on: 'insert.text',
  guard: ({event, snapshot}) => event.text === 'a',
  actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],
})
```