Skip to content

Commit

Permalink
Clarify the use of useFuture (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwill39 authored Jan 4, 2024
1 parent 3b17a96 commit e35a92a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/flutter_hooks/lib/src/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ part of 'hooks.dart';
/// * [preserveState] determines if the current value should be preserved when changing
/// the [Future] instance.
///
/// The [Future] needs to be created outside of [useFuture].
/// If the [Future] is created inside [useFuture], then, every time the build
/// method gets called, the [Future] will be called again. One way to create
/// the [Future] outside of [useFuture] is by using [useMemoized].
///
/// ```dart
/// // BAD
/// useFuture(fetchFromDatabase());
///
/// // GOOD
/// final result = useMemoized(() => fetchFromDatabase());
/// useFuture(result);
/// ```
///
/// See also:
/// * [Future], the listened object.
/// * [useStream], similar to [useFuture] but for [Stream].
Expand Down

0 comments on commit e35a92a

Please sign in to comment.