useCallback<T extends Function> function

T useCallback<T extends Function>(
  1. T callback, [
  2. List<Object?> keys = const <Object>[]
])

Cache a function across rebuilds based on a list of keys.

This is syntax sugar for useMemoized, so that instead of:

final cachedFunction = useMemoized(() => () {
  print('doSomething');
}, [key]);

we can directly do:

final cachedFunction = useCallback(() {
  print('doSomething');
}, [key]);

Implementation

T useCallback<T extends Function>(
  T callback, [
  List<Object?> keys = const <Object>[],
]) {
  return useMemoized(() => callback, keys);
}