useQuery()
Call Signature
function useQuery<TData, TError>(options, queryClient?): UseQueryResult<TData, TError>
Uses the queryFn to execute the query. No different from the base useQuery hook.
Type Parameters
| Type Parameter | Default type |
|---|---|
TData | unknown |
TError | Error |
Parameters
| Parameter | Type |
|---|---|
options | UseQueryOptions<TData, TError, TData, readonly unknown[]> & PowerSyncQueryOptions<any> & { query: undefined; } |
queryClient? | QueryClient |
Returns
UseQueryResult<TData, TError>
Example
const { data, error, isLoading } = useQuery({
queryKey: ['lists'],
queryFn: getTodos,
});
Call Signature
function useQuery<TData, TError>(options, queryClient?): UseQueryResult<TData[], TError>
Uses the query to execute the PowerSync query.
Type Parameters
| Type Parameter | Default type |
|---|---|
TData | unknown |
TError | Error |
Parameters
| Parameter | Type |
|---|---|
options | UseQueryOptions<TData[], TError, TData[], readonly unknown[]> & PowerSyncQueryOptions<any> & { query: string | CompilableQuery<TData>; } |
queryClient? | QueryClient |
Returns
UseQueryResult<TData[], TError>
Examples
const { data, error, isLoading } = useQuery({
queryKey: ['lists'],
query: 'SELECT * from lists where id = ?',
parameters: ['id-1']
});
const { data, error, isLoading } = useQuery({
queryKey: ['lists'],
query: compilableQuery,
});