How to migrate code after ref.state deprecation in Riverpod? #3967
Replies: 3 comments 1 reply
-
Refactor to an AsyncNotifier |
Beta Was this translation helpful? Give feedback.
-
Thank you, @rrousselGit, for your response! I'm evaluating the best approach to migrate around 30 FutureProviders, some containing complex logic such as search and filtering. Based on your suggestion, I’ve experimented with both AsyncNotifier and StateNotifier. I understand that your library evolves over time to improve state management, which sometimes leads to deprecations. To minimize the risk of having to refactor again in the near future, I’d like to make an informed decision. Given the current state of Riverpod, would you recommend AsyncNotifier over StateNotifier, or do you see a strong case for preferring one over the other? Below are my simplified implementations for handling data retrieval in an infinite scrolling list: Using StateNotifier
Using AsyncNotifier
Would love to hear your insights on which approach is more future-proof and aligns better with Riverpod’s roadmap. Thanks in advance for your guidance! |
Beta Was this translation helpful? Give feedback.
-
Hi @rrousselGit, I managed to refactor part of my codebase using AsyncNotifier, and it has been working well so far. Now, I’m trying to migrate my existing .family providers that accept parameters. Use Case
Existing Implementations Vehicles List Provider
Payment Methods List Provider
Invoices List with a Parameter I’m looking for something like this:
How can I correctly pass the InvoiceType parameter to the InvoicesListNotifier when using AsyncNotifierProvider.family? I would appreciate your guidance on the best approach. Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
-
I just noticed that ref.state is deprecated, and I am using it in many providers in my application.
This is a simplified example of how I use it to get a list of invoices:
The
ref.state.value?.paginator.next_page_url
contains the URL of the next page of the result. So when I call:ref.invalidate(invoicesListFutureProvider);
it loads the next page, making use of the state.value?.paginator.next_page_url from the previous call.Now that
ref.state
is deprecated, how should I migrate my code to be compatible with Riverpod?Beta Was this translation helpful? Give feedback.
All reactions