Skip to content
Source
Sign inSign up
TanStack/db

feat(vue-db): implement useLiveInfiniteQuery for vue 3 #1513

Closedmiguelrk(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1513/headopened

Showing 6 changed files with 57 additions and 0 deletions (loading 4).

x
0 of 6 viewed, 6 left
56 additions and 0 deletions.changeset/vue-infinite-query.mdAdded
View file
@@ -0,0 +1,56 @@
+---
+'@tanstack/vue-db': minor
+---
+​
+Add `useLiveInfiniteQuery` composable for infinite scrolling with live updates.
+​
+The new `useLiveInfiniteQuery` provides an infinite query pattern similar to TanStack Query's `useInfiniteQuery`, but integrated with TanStack DB's reactive local collections. It maintains a reactive window into your data, allowing for efficient pagination and automatic updates as data changes.
+​
+**Key features:**
+​
+- **Automatic Live Updates**: Reactive integration with local collections using Vue 3 composables (ref, computed, watchEffect).
+- **Efficient Pagination**: Uses a dynamic window mechanism to track visible data without re-executing complex queries.
+- **Automatic Page Detection**: Includes a built-in peek-ahead strategy to detect if more pages are available without manual `getNextPageParam` logic.
+- **Flexible Rendering**: Provides both a flattened `data` ref and a structured `pages` ref.
+​
+**Example usage:**
+​
+```vue
+<script setup lang="ts">
+import { useLiveInfiniteQuery } from "@tanstack/vue-db";
+import { postsCollection } from "./db";
+​
+const { data, pages, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } =
+ useLiveInfiniteQuery(
+ (q) =>
+ q
+ .from({ posts: postsCollection })