useSubscribeToRecordList

useSubscribeToRecordList subscribes to the resource/<name> topic for a whole resource collection. It fires on created, updated, and deleted events for any record in the collection.

Usage

import { useSubscribeToRecordList } from "@/components/realtime";
import { useQueryClient } from "@tanstack/react-query";
 
function PostsWatcher() {
  const queryClient = useQueryClient();
  useSubscribeToRecordList("posts", () => {
    queryClient.invalidateQueries({ predicate: (q) => q.queryKey[0] === "posts" });
  });
  return null;
}

Params

ParamRequiredTypeDescription
resourceRequiredstringResource name
callbackRequired(event: RealtimeEvent) => voidCalled for each event on the resource topic
options.enabledOptionalbooleanDefault true. Set to false to pause the subscription

Returns

void

Notes

  • The topic format is resource/<resource> — constructed by the resourceTopic() helper.
  • This is the hook used internally by <ListLive>. Use it directly when you need list-level live updates outside a <List> component.