Skip to main content
API Reference / @modelence/react-query / modelenceLiveQuery
modelenceLiveQuery<T>(methodName, args): object
Defined in: index.ts:146 Creates query options for live queries with TanStack Query’s useQuery hook. Data will be updated in real-time when underlying data changes. Requires ModelenceQueryClient to be connected to your QueryClient.

Example

import { useQuery } from '@tanstack/react-query';
import { modelenceLiveQuery } from '@modelence/react-query';

function TodoList() {
  // Subscribe to live updates - data refreshes automatically when todos change
  const { data: todos } = useQuery(modelenceLiveQuery('todo.getAll', { userId }));

  return (
    <ul>
      {todos?.map(todo => <li key={todo._id}>{todo.title}</li>)}
    </ul>
  );
}

Type Parameters

Type ParameterDefault typeDescription
TunknownThe expected return type of the query

Parameters

ParameterTypeDescription
methodNamestringThe name of the method to query
argsArgsOptional arguments to pass to the method

Returns

object Query options object for TanStack Query’s useQuery
NameTypeDefault valueDefined in
gcTimenumber0index.ts:207
queryFn()() => Promise<T>-index.ts:155
queryKeyreadonly ["live", string, Args]-index.ts:154
refetchOnMountbooleanfalseindex.ts:205
refetchOnReconnectbooleanfalseindex.ts:206
refetchOnWindowFocusbooleanfalseindex.ts:204
staleTimenumberInfinityindex.ts:203