rrousselGit / flutter_hooks

React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
MIT License
3.07k stars 175 forks source link

Making the `keys` optional for the `useCallback` hook #368

Closed jezsung closed 12 months ago

jezsung commented 12 months ago

Maybe I'm missing something, but why does the keys property on the useCallback have to be required? The useMemonized has its keys optional and it defaults to an empty list.

Below is the current implementation of the useCallback hook:

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

I wonder if we could change the keys property optional and default to an empty list like the following:

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

Sure. Fancy making a PR?

jezsung commented 12 months ago

@rrousselGit Sure, I'll make a PR asap