Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions docs/framework/react/reference/functions/useLiveQueryEffect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
id: useLiveQueryEffect
title: useLiveQueryEffect
---

# Function: useLiveQueryEffect()

```ts
function useLiveQueryEffect<TRow, TKey>(config, deps): void;
```

Defined in: [useLiveQueryEffect.ts:30](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQueryEffect.ts#L30)

React hook for creating a reactive effect that fires handlers when rows
enter, exit, or update within a query result.

The effect is created on mount and disposed on unmount. If `deps` change,
the previous effect is disposed and a new one is created.

## Type Parameters

### TRow

`TRow` *extends* `object` = `Record`\<`string`, `unknown`\>

### TKey

`TKey` *extends* `string` \| `number` = `string` \| `number`

## Parameters

### config

`EffectConfig`\<`TRow`, `TKey`\>

### deps

`DependencyList` = `[]`

## Returns

`void`

## Example

```tsx
function ChatComponent() {
useLiveQueryEffect(
{
query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),
skipInitial: true,
onEnter: async (event) => {
await generateResponse(event.value)
},
},
[]
)

return <div>...</div>
}
```
1 change: 1 addition & 0 deletions docs/framework/react/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ title: "@tanstack/react-db"

- [useLiveInfiniteQuery](functions/useLiveInfiniteQuery.md)
- [useLiveQuery](functions/useLiveQuery.md)
- [useLiveQueryEffect](functions/useLiveQueryEffect.md)
- [useLiveSuspenseQuery](functions/useLiveSuspenseQuery.md)
- [usePacedMutations](functions/usePacedMutations.md)
51 changes: 51 additions & 0 deletions docs/reference/functions/createEffect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
id: createEffect
title: createEffect
---

# Function: createEffect()

```ts
function createEffect<TRow, TKey>(config): Effect;
```

Defined in: [packages/db/src/query/effect.ts:184](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L184)

Creates a reactive effect that fires handlers when rows enter, exit, or
update within a query result. Effects process deltas only — they do not
maintain or require the full materialised query result.

## Type Parameters

### TRow

`TRow` *extends* `object` = `Record`\<`string`, `unknown`\>

### TKey

`TKey` *extends* `string` \| `number` = `string` \| `number`

## Parameters

### config

[`EffectConfig`](../interfaces/EffectConfig.md)\<`TRow`, `TKey`\>

## Returns

[`Effect`](../interfaces/Effect.md)

## Example

```typescript
const effect = createEffect({
query: (q) => q.from({ msg: messagesCollection })
.where(({ msg }) => eq(msg.role, 'user')),
onEnter: async (event) => {
await generateResponse(event.value)
},
})

// Later: stop the effect
await effect.dispose()
```
7 changes: 7 additions & 0 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ title: "@tanstack/db"
- [CurrentStateAsChangesOptions](interfaces/CurrentStateAsChangesOptions.md)
- [DebounceStrategy](interfaces/DebounceStrategy.md)
- [DebounceStrategyOptions](interfaces/DebounceStrategyOptions.md)
- [Effect](interfaces/Effect.md)
- [EffectConfig](interfaces/EffectConfig.md)
- [EffectContext](interfaces/EffectContext.md)
- [IndexInterface](interfaces/IndexInterface.md)
- [IndexOptions](interfaces/IndexOptions.md)
- [IndexStats](interfaces/IndexStats.md)
Expand Down Expand Up @@ -167,6 +170,9 @@ title: "@tanstack/db"
- [DeleteKeyMessage](type-aliases/DeleteKeyMessage.md)
- [DeleteMutationFn](type-aliases/DeleteMutationFn.md)
- [DeleteMutationFnParams](type-aliases/DeleteMutationFnParams.md)
- [DeltaEvent](type-aliases/DeltaEvent.md)
- [DeltaType](type-aliases/DeltaType.md)
- [EffectQueryInput](type-aliases/EffectQueryInput.md)
- [ExtractContext](type-aliases/ExtractContext.md)
- [FieldPath](type-aliases/FieldPath.md)
- [Fn](type-aliases/Fn.md)
Expand Down Expand Up @@ -257,6 +263,7 @@ title: "@tanstack/db"
- [createArrayChangeProxy](functions/createArrayChangeProxy.md)
- [createChangeProxy](functions/createChangeProxy.md)
- [createCollection](functions/createCollection.md)
- [createEffect](functions/createEffect.md)
- [createLiveQueryCollection](functions/createLiveQueryCollection.md)
- [createOptimisticAction](functions/createOptimisticAction.md)
- [createPacedMutations](functions/createPacedMutations.md)
Expand Down
38 changes: 38 additions & 0 deletions docs/reference/interfaces/Effect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
id: Effect
title: Effect
---

# Interface: Effect

Defined in: [packages/db/src/query/effect.ts:134](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L134)

Handle returned by createEffect

## Properties

### dispose()

```ts
dispose: () => Promise<void>;
```

Defined in: [packages/db/src/query/effect.ts:136](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L136)

Dispose the effect. Returns a promise that resolves when in-flight handlers complete.

#### Returns

`Promise`\<`void`\>

***

### disposed

```ts
readonly disposed: boolean;
```

Defined in: [packages/db/src/query/effect.ts:138](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L138)

Whether this effect has been disposed
156 changes: 156 additions & 0 deletions docs/reference/interfaces/EffectConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
id: EffectConfig
title: EffectConfig
---

# Interface: EffectConfig\<TRow, TKey\>

Defined in: [packages/db/src/query/effect.ts:93](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L93)

Effect configuration

## Type Parameters

### TRow

`TRow` *extends* `object` = `Record`\<`string`, `unknown`\>

### TKey

`TKey` *extends* `string` \| `number` = `string` \| `number`

## Properties

### id?

```ts
optional id: string;
```

Defined in: [packages/db/src/query/effect.ts:98](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L98)

Optional ID for debugging/tracing

***

### onBatch?

```ts
optional onBatch: EffectBatchHandler<TRow, TKey>;
```

Defined in: [packages/db/src/query/effect.ts:113](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L113)

Called once per graph run with all delta events from that batch

***

### onEnter?

```ts
optional onEnter: EffectEventHandler<TRow, TKey>;
```

Defined in: [packages/db/src/query/effect.ts:104](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L104)

Called once for each row entering the query result

***

### onError()?

```ts
optional onError: (error, event) => void;
```

Defined in: [packages/db/src/query/effect.ts:116](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L116)

Error handler for exceptions thrown by effect callbacks

#### Parameters

##### error

`Error`

##### event

[`DeltaEvent`](../type-aliases/DeltaEvent.md)\<`TRow`, `TKey`\>

#### Returns

`void`

***

### onExit?

```ts
optional onExit: EffectEventHandler<TRow, TKey>;
```

Defined in: [packages/db/src/query/effect.ts:110](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L110)

Called once for each row exiting the query result

***

### onSourceError()?

```ts
optional onSourceError: (error) => void;
```

Defined in: [packages/db/src/query/effect.ts:123](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L123)

Called when a source collection enters an error or cleaned-up state.
The effect is automatically disposed after this callback fires.
If not provided, the error is logged to console.error.

#### Parameters

##### error

`Error`

#### Returns

`void`

***

### onUpdate?

```ts
optional onUpdate: EffectEventHandler<TRow, TKey>;
```

Defined in: [packages/db/src/query/effect.ts:107](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L107)

Called once for each row updating within the query result

***

### query

```ts
query: EffectQueryInput<any>;
```

Defined in: [packages/db/src/query/effect.ts:101](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L101)

Query to watch for deltas

***

### skipInitial?

```ts
optional skipInitial: boolean;
```

Defined in: [packages/db/src/query/effect.ts:130](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L130)

Skip deltas during initial collection load.
Defaults to false (process all deltas including initial sync).
Set to true for effects that should only process new changes.
34 changes: 34 additions & 0 deletions docs/reference/interfaces/EffectContext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: EffectContext
title: EffectContext
---

# Interface: EffectContext

Defined in: [packages/db/src/query/effect.ts:67](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L67)

Context passed to effect handlers

## Properties

### effectId

```ts
effectId: string;
```

Defined in: [packages/db/src/query/effect.ts:69](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L69)

ID of this effect (auto-generated if not provided)

***

### signal

```ts
signal: AbortSignal;
```

Defined in: [packages/db/src/query/effect.ts:71](https://github.com/TanStack/db/blob/main/packages/db/src/query/effect.ts#L71)

Aborted when effect.dispose() is called
Loading