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