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.13k stars 179 forks source link

Reduce boilerplate code of controller (ChangeNotifier) hooks #415

Closed yelliver closed 2 months ago

yelliver commented 7 months ago

If this PR is merged, I will group all of them into a single file, making the repo cleaner.

rrousselGit commented 7 months ago

That looks interesting.

A few things:

yelliver commented 7 months ago

That looks interesting.

A few things:

  • We'd need tests for the new hooks
  • They should be added to the readme and the changelog
rrousselGit commented 7 months ago

If we don't expose useChangeNotifier & useDispose, do we need any info in readme?

No but then we should mark those as @internal

rrousselGit commented 7 months ago

I think the new hooks are used by existing hooks (which are changed in implementation) so their existing test cases should cover, how do you think?

Not if we export those hooks.

rrousselGit commented 7 months ago

:wave: Do you still wish to work on this? If so, we need to decide wether you want those hooks part of the public API, or be internal only (and therefore not exported).

yelliver commented 7 months ago

Let's recap:

I prefer to export them, if you think it is proper, I will add test cases for them.

rrousselGit commented 7 months ago

If we want to export them, I'll also be a bit more strict on the API.

yelliver commented 7 months ago

which restriction do you want to change? I will change it. But I think I am going to make it internal by hiding it to make this PR move forward first.

lvsecoto commented 6 months ago

I think we need to export them, to reduce these boring code:

      final controller = useMemoized(
        () => SomeChangeNotifier(),
      );
      useEffect(
        () => () {
          controller.dispose();
        },
        [controller],
      );
rrousselGit commented 6 months ago

I don't like the API of that useDispose. Especially that label parameter. It feels out of place, considering that's a debug only thing.

If we want a reusable hook for this, I'd like a more Riverpod-like API.

final model = useValue((ref) {
  // Offer various life-cycles
  ref.onDispose(...);
  ref.state = ...;
  ref.notifyListeners();
  return MyModel();
}, [keys]);

This merges various hooks in a single API.

rrousselGit commented 2 months ago

This appears to be stale, so I'll close this :)

Feel free to reopen a PR if you want to resume working on this