tanquery 0.1.0 copy "tanquery: ^0.1.0" to clipboard
tanquery: ^0.1.0 copied to clipboard

TanStack Query for Dart. Automatic caching, stale-while-revalidate, background refetching, mutations with optimistic updates, infinite queries. Pure Dart - no Flutter dependency.

example/tanquery_example.dart

import 'package:tanquery/tanquery.dart';

Future<List<String>> fetchTodos() async {
  await Future.delayed(const Duration(seconds: 1));
  return ['Buy milk', 'Walk the dog', 'Write code'];
}

void main() async {
  final client = QueryClient();
  client.mount();

  // Fetch and cache data
  final todos = await client.fetchQuery<List<String>>(
    queryKey: QueryKey(['todos']),
    queryFn: fetchTodos,
  );
  print('Fetched ${todos.length} todos');

  // Read from cache
  final cached = client.getQueryData<List<String>>(QueryKey(['todos']));
  print('Cached: $cached');

  // Invalidate (marks as stale)
  await client.invalidateQueries(queryKey: QueryKey(['todos']));
  print('Invalidated todos');

  // Set data manually
  client.setQueryData<List<String>>(
    QueryKey(['todos']),
    (List<String> old) => [...old, 'New todo'],
  );
  print('Updated: ${client.getQueryData<List<String>>(QueryKey(["todos"]))}');

  client.unmount();
}
4
likes
0
points
179
downloads

Publisher

verified publisherottomancoder.com

Weekly Downloads

TanStack Query for Dart. Automatic caching, stale-while-revalidate, background refetching, mutations with optimistic updates, infinite queries. Pure Dart - no Flutter dependency.

Repository (GitHub)
View/report issues

Topics

#cache #state-management #query #api #data-fetching

License

unknown (license)

Dependencies

meta

More

Packages that depend on tanquery