useCallback<T extends Function> function Null safety

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

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

This is syntax sugar for useMemoized, such 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,
) {
  return useMemoized(() => callback, keys);
}