---
url: /api/kiln/functions/despawnOnExit.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / despawnOnExit

# Function: despawnOnExit()

```ts
function despawnOnExit<S>(s, value): [Trait<{
  state: string;
  value: string;
}>, Partial<{
  state: string;
  value: string;
}>];
```

The DespawnOnExit trait for a state value: `commands.spawn(Enemy, ..., despawnOnExit(Screen, 'playing'))`.

## Type Parameters

| Type Parameter |
| ------ |
| `S` *extends* `string` |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `s` | [`State`](../interfaces/State.md)<`S`> |
| `value` | `S` |

## Returns

\[`Trait`<{
`state`: `string`;
`value`: `string`;
}>, `Partial`<{
`state`: `string`;
`value`: `string`;
}>]
