Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ProviderSubscription read inside useEffect dispose. #3491

Open
a1573595 opened this issue Apr 12, 2024 · 0 comments
Open

Support ProviderSubscription read inside useEffect dispose. #3491

a1573595 opened this issue Apr 12, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@a1573595
Copy link

Is your feature request related to a problem? Please describe.
Reference #3486. I want to lazily load data when entering the page, cache them after the data is loaded, and release them when leaving the page.

Describe the solution you'd like
As shown below, support sub.read processing inside useEffect, which will currently throw an error(Bad state: called ProviderSubscription.read on a subscription that was closed).

useEffect(() {
      final subscription = ref.listenManual(Provider, (prev, next) {});

      return () {
        ref.read(Provider.notifier).update((state) => !state);
        subscription.close();
      };
}, const []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants