qora_hooks library

flutter_hooks integration for Qora.

Provides useQuery, useMutation, useQueryClient, and useInfiniteQuery — the hook-based counterparts of QoraBuilder and QoraMutationBuilder.

Quick start

// Wrap your app with QoraScope (from flutter_qora):
runApp(
  QoraScope(
    client: QoraClient(),
    child: MyApp(),
  ),
);

// Then use hooks inside any HookWidget:
class UserScreen extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final state = useQuery<User>(
      key: ['users', '42'],
      fetcher: () => api.getUser('42'),
    );
    return switch (state) {
      Loading() => const CircularProgressIndicator(),
      Success(:final data) => Text(data.name),
      Failure(:final error) => Text('$error'),
      _ => const SizedBox.shrink(),
    };
  }
}

Classes

InfiniteQueryHandle<TData, TPageParam>
Groups all pagination state returned by useInfiniteQuery.
MutationHandle<TData, TVariables>
Groups the current MutationState and the action callbacks returned by useMutation.

Functions

useInfiniteQuery<TData, TPageParam>({required List<Object?> key, required Future<TData> fetcher(TPageParam pageParam), required TPageParam? getNextPageParam(TData lastPage), required TPageParam initialPageParam, QoraOptions? options}) InfiniteQueryHandle<TData, TPageParam>
Hook for paginated / infinite-scroll queries.
useMutation<TData, TVariables>({required Future<TData> mutator(TVariables variables), MutationOptions<TData, TVariables, void>? options}) MutationHandle<TData, TVariables>
Hook for triggering a mutation and tracking its lifecycle state.
useQuery<T>({required List<Object?> key, required Future<T> fetcher(), QoraOptions? options}) → QoraState<T>
Subscribes to a QoraClient query and returns the current QoraState.
useQueryClient() → QoraClient
Returns the nearest QoraClient from the widget tree.