API reference / @evolu/react-native / web / useQuery
Variable: useQuery()
const useQuery: <R>(query, options?) => QueryRows<R>;
Defined in: react/dist/useQuery.d.ts:31
Load and subscribe to the Query, and return an object with rows
and row
properties that are automatically updated when data changes.
Note that useQuery uses React Suspense. It means every usage of useQuery blocks rendering until loading is completed. To avoid loading waterfall with more queries, use useQueries.
Example
// Get all rows.
const rows = useQuery(allTodos);
// Get rows for a specific todo (the first row can be null).
const rows = useQuery(todoById(1));
// Get all rows, but without subscribing to changes.
const rows = useQuery(allTodos, { once: true });
// Prefetch rows.
const allTodos = evolu.createQuery((db) =>
db.selectFrom("todo").selectAll(),
);
const allTodosPromise = evolu.loadQuery(allTodos);
// Use prefetched rows.
const rows = useQuery(allTodos, { promise: allTodosPromise });
Type Parameters
Type Parameter |
---|
R extends Row |
Parameters
Parameter | Type |
---|---|
query | Query <R > |
options? | Partial <{ once : boolean ; promise : Promise <QueryRows <R >>; }> |
Returns
QueryRows
<R
>