useFuture top-level property

Creates a reactive signal that tracks the state of a Future.

This hook provides an AsyncSnapshot that updates automatically as the Future progresses through its lifecycle. The behavior matches FutureBuilder.

Parameters:

  • future: The Future to track, can be null
  • initialData: Optional initial data to use before the Future completes

Example:

final future = Future.delayed(Duration(seconds: 1), () => 42);
final snapshot = useFuture(future);

if (snapshot.connectionState == ConnectionState.waiting) {
  return CircularProgressIndicator();
} else if (snapshot.hasError) {
  return Text('Error: ${snapshot.error}');
} else {
  return Text('Data: ${snapshot.data}');
}

Implementation

@defineHook
final useFuture = JoltUseFutureHookCreator._();