Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

getactivetransaction.md

36 lines897 Bytes

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