useCallback<T extends Function> function

T useCallback<T extends Function>(
  1. T callback,
  2. List dependencies
)

Returns a memoized version of callback that only changes if one of the dependencies has changed.

Note: there are two rules for using Hooks:

Example:

UseCallbackTestComponent(Map props) {
  final count = useState(0);
  final delta = useState(1);

  var increment = useCallback((_) {
    count.setWithUpdater((prev) => prev + delta.value);
  }, [delta.value]);

  var incrementDelta = useCallback((_) {
    delta.setWithUpdater((prev) => prev + 1);
  }, []);

  return react.div({}, [
    react.div({}, ['Delta is ${delta.value}']),
    react.div({}, ['Count is ${count.value}']),
    react.button({'onClick': increment}, ['Increment count']),
    react.button({'onClick': incrementDelta}, ['Increment delta']),
  ]);
}

Learn more: reactjs.org/docs/hooks-reference.html#usecallback.

Implementation

T useCallback<T extends Function>(T callback, List dependencies) =>
    React.useCallback(allowInterop(callback), dependencies) as T;