Open History to see the last commit
1---
2id: getActiveTransaction
3title: getActiveTransaction
4---
5
6# Function: getActiveTransaction()
7
8```ts
9function getActiveTransaction():
10 | Transaction<Record<string, unknown>>
11 | undefined;
12```
13
14Defined in: [packages/db/src/transactions.ts:300](https://github.com/TanStack/db/blob/main/packages/db/src/transactions.ts#L300)
15
16Gets the currently active ambient transaction, if any
17Used internally by collection operations to join existing transactions
18
19## Returns
20
21 \| [`Transaction`](../interfaces/Transaction.md)\<`Record`\<`string`, `unknown`\>\>
22 \| `undefined`
23
24The active transaction or undefined if none is active
25
26## Example
27
28```ts
29// Check if operations will join an ambient transaction
30const ambientTx = getActiveTransaction()
31if (ambientTx) {
32 console.log('Operations will join transaction:', ambientTx.id)
33}
34```