github TanStack/db @tanstack/react-db@0.1.21

latest releases: @tanstack/vue-db@0.0.54, @tanstack/trailbase-db-collection@0.1.21, @tanstack/svelte-db@0.1.21...
16 hours ago

Patch Changes

  • Expand useLiveQuery callback to support conditional queries and additional return types, enabling the ability to temporarily disable the query. (#535)

    New Features:

    • Callback can now return undefined or null to temporarily disable the query
    • Callback can return a pre-created Collection instance to use it directly
    • Callback can return a LiveQueryCollectionConfig object for advanced configuration
    • When disabled (returning undefined/null), the hook returns a specific idle state

    Usage Examples:

    // Conditional queries - disable when not ready
    const enabled = useState(false)
    const { data, state, isIdle } = useLiveQuery((q) => {
      if (!enabled) return undefined  // Disables the query
      return q.from({ users }).where(...)
    }, [enabled])
    
    /**
     * When disabled, returns:
     * {
     *   state: undefined,
     *   data: undefined,
     *   isIdle: true,
     *   ...
     * }
     */
    
    // Return pre-created Collection
    const { data } = useLiveQuery((q) => {
      if (usePrebuilt) return myCollection  // Use existing collection
      return q.from({ items }).select(...)
    }, [usePrebuilt])
    
    // Return LiveQueryCollectionConfig
    const { data } = useLiveQuery((q) => {
      return {
        query: q.from({ items }).select(...),
        id: `my-collection`,
      }
    })
  • Updated dependencies [cacfca2]:

    • @tanstack/db@0.3.2

Don't miss a new db release

NewReleases is sending notifications on new releases.