npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@valian/react-query-observable

v1.3.3

Published

react query rxjs observable

Readme

@valian/react-query-observable

React Query options for RxJS observables. This package provides utilities to seamlessly integrate RxJS observables with TanStack Query (React Query), enabling reactive data fetching with automatic caching, background updates, error handling, and subscription lifecycle management.

npm version License: MIT

Installation

pnpm add @valian/react-query-observable

Peer Dependencies

  • @tanstack/react-query ^5.80.0
  • rxjs ^7.8.0

Features

  • 🔄 Reactive data fetching: Use RxJS Observables as data sources for TanStack Query
  • 🧠 Smart caching: First emission resolves the query; later emissions update cache
  • ♻️ Automatic subscription cleanup: Subscriptions are tied to query lifecycle
  • 🛡️ Error handling: Pre-first-value errors reject the query; post-first-value errors surface to the runtime
  • 🧭 Dynamic staleness: staleTime is Infinity while subscribed, otherwise 0
  • 📦 TypeScript first: Strong types for options and observable function

Quick Start

import { useQuery } from '@tanstack/react-query'
import { interval, map, take } from 'rxjs'
import { observableQueryOptions } from '@valian/react-query-observable'

function MyComponent() {
  const { data, isLoading, error } = useQuery(
    observableQueryOptions({
      queryKey: ['ticker'],
      observableFn: () => interval(1000).pipe(take(1), map((i) => ({ tick: i }))),
    }),
  )

  if (isLoading) return <div>Loading…</div>
  if (error) return <div>Error: {(error as Error).message}</div>
  return <div>Tick: {data?.tick}</div>
}

API

observableQueryOptions

Creates TanStack Query options from an RxJS observable function.

function observableQueryOptions<
  TQueryFnData = unknown,
  TError = DefaultError,
  TData = TQueryFnData,
  TQueryKey extends QueryKey = QueryKey,
>(options: ObservableQueryOptions<TQueryFnData, TError, TData, TQueryKey>)

Parameters (selected)

  • observableFn (required): (ctx: QueryFunctionContext<TQueryKey>) => Observable<TQueryFnData>
  • queryKey (required): TQueryKey
  • Any other standard Query Options are accepted except those managed automatically (see below).

Managed options

These are controlled internally and thus omitted from ObservableQueryOptions:

  • queryFn: generated from observableFn
  • staleTime: Infinity when there is an active subscription for queryKey, else 0
  • retry: false
  • Refetch-related flags: refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnMount, refetchOnReconnect, retryOnMount

Other defaults

  • gcTime: 10_000 (can be overridden)

Behavior Details

  • The first value emitted by the observable resolves the query promise.
  • Subsequent emissions update the cached data via client.setQueryData for the same queryKey.
  • If the observable errors before the first value, the query promise rejects with that error.
  • If the observable errors after the first value, the error is thrown in the subscription context (outside the original promise). Handle these via RxJS or global error handlers if needed.
  • When the query is removed from the cache, the active subscription for the corresponding queryKey is automatically unsubscribed.

Advanced Examples

WebSocket stream

import { webSocket } from 'rxjs/webSocket'
import { map, retry } from 'rxjs/operators'

const { data } = useQuery(
  observableQueryOptions({
    queryKey: ['live-prices', symbol],
    observableFn: () =>
      webSocket<{ price: number }>(`wss://example.com/${symbol}`).pipe(
        map((msg) => msg.price),
        retry({ delay: 1000 }),
      ),
  }),
)

Combine multiple sources

import { combineLatest } from 'rxjs'
import { map } from 'rxjs/operators'

const { data } = useQuery(
  observableQueryOptions({
    queryKey: ['user-profile', userId],
    observableFn: () =>
      combineLatest([fetchUser(userId), fetchUserPosts(userId), fetchFollowers(userId)]).pipe(
        map(([user, posts, followers]) => ({ user, posts, followers })),
      ),
  }),
)

TypeScript Usage

interface Todo {
  id: number
  title: string
  completed: boolean
}

const { data } = useQuery(
  observableQueryOptions<Todo[]>({
    queryKey: ['todos'],
    observableFn: () => fetchTodos$(),
  }),
)
// data: Todo[] | undefined

License

MIT © Valian