Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

TanStack DB

A reactive client store for building super fast apps on sync

TanStack DB extends TanStack Query with collections, live queries and optimistic mutations that keep your UI reactive, consistent and blazing fast 🔥

#TanStackStatus - BETAJoin the discussion on Github

Enjoy this library? Try the entire TanStack, including TanStack Query, TanStack Store, etc.

🚀 Why TanStack DB?

TanStack DB gives you robust support for real-time sync, live queries and local writes. With no stale data, super fast re-rendering and sub-millisecond cross-collection queries — even for large complex apps.

Built on a TypeScript implementation of differential dataflow (#), TanStack DB gives you:

  • 🔥 a blazing fast query engine
    for sub-millisecond live queries — even for complex queries with joins and aggregates
  • 🎯 fine-grained reactivity
    to minimize component re-rendering
  • 💪 robust transaction primitives
    for easy optimistic mutations with sync and lifecycle support
  • 🌟 normalized data
    to keep your backend simple

TanStack DB is backend agnostic and incrementally adoptable:

  • plug in any backend: sync engines, REST APIs, GraphQL, polling, custom sources
  • builds on TanStack Store, works with and alongside TanStack Query

💥 Usage example

Sync data into collections:

import{createCollection,QueryClient}from"@tanstack/react-db"import{queryCollectionOptions}from"@tanstack/query-db-collection"consttodoCollection=createCollection(queryCollectionOptions({queryKey: ["todos"],queryFn: async()=>fetch("/api/todos"),queryClient: newQueryClient(),getKey: (item)=>item.id,schema: todoSchema,// any standard schema}))

Use live queries in your components:

import{useLiveQuery}from"@tanstack/react-db"import{eq}from"@tanstack/db"constTodos=()=>{const{data: todos}=useLiveQuery((query)=>query.from({todos: todoCollection}).where(({ todos })=>eq(todos.completed,false)))return<Listitems={todos}/>}

Apply mutations with local optimistic state:

// Define collection with persistence handlersconsttodoCollection=createCollection({id: "todos",// ... other configonInsert: async({ transaction })=>{constmodified=transaction.mutations[0].modifiedawaitapi.todos.create(modified)},})// Then use collection operators in your componentsconstAddTodo=()=>{return(<ButtononClick={()=>todoCollection.insert({id: uuid(),text: "🔥 Make app faster",completed: false,})}/>)}

📚 Docs

See the Usage guide for more details, including how to do:

  • real-time sync
  • cross-collection queries
  • fine-grained reactivity
  • different strategies for data loading and handling mutations

There's also an example React todo app and usage examples in the package tests.

🧱 Core concepts

Collections

  • typed sets of objects that can mirror a backend table or be populated with a filtered view or result set, such as pendingTodos or decemberNewTodos
  • collections are just JavaScript data — load them on demand and define as many as you need

Live queries

  • run reactively against and across collections with support for joins, filters and aggregates
  • powered by differential dataflow: query results update incrementally, not by re-running the whole query

Transactional mutators

  • batch and stage local changes across collections with immediate application of local optimistic updates
  • sync transactions to the backend with automatic rollbacks and management of optimistic state

📦 Collection Types

TanStack DB provides several collection types to support different backend integrations:

  • @tanstack/db - Core collection functionality with local-only and local-storage collections for offline-first applications
  • @tanstack/query-db-collection - Collections backed by TanStack Query for REST APIs and GraphQL endpoints
  • @tanstack/electric-db-collection - Real-time sync collections powered by ElectricSQL for live database synchronization
  • @tanstack/trailbase-db-collection - Collections for TrailBase backend integration

Framework integrations

TanStack DB integrates with React & Vue with more on the way!

  • @tanstack/react-db - React hooks and components for using TanStack DB collections in React applications
  • @tanstack/vue-db - Vue composables for using TanStack DB collections in Vue applications

🔧 Install

npm install @tanstack/react-db
# Optional: for specific collection types
npm install @tanstack/electric-db-collection @tanstack/query-db-collection

Other framework integrations are in progress.

❓ FAQ

How is this different from TanStack Query?
TanStack DB builds on top of TanStack Query. Use Query to fetch data; use DB to manage reactive local collections and mutations. They complement each other.

Do I need a sync engine like ElectricSQL?
No. TanStack DB is designed to work with sync engines like Electric but also works with any backend: polling APIs, GraphQL, REST, or custom sync logic.

What is a Collection? Is it like a DB table?
Kind of. Collections are typed sets of objects, but they can also be filtered views or custom groupings. They're just JavaScript structures that you define and manage.

Is this an ORM? Do queries hit my backend?
No. TanStack DB is not an ORM. Queries run entirely in the client against local collections. The framework provides strong primitives to manage how data is loaded and synced.

Partners

ElectricSQL logo

Status

Tanstack DB is currently in BETA. See the release post for more details.

Contributing

View the contributing guidelines here.

About

A reactive client store for building super fast apps

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages