Should a provider invoke another provider side-effect? #3523
Unanswered
thangmoxielabs
asked this question in
Q&A
Replies: 2 comments 1 reply
-
No. It falls under: https://riverpod.dev/docs/essentials/do_dont#dont-perform-side-effects-during-the-initialization-of-a-provider |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yea that makes sense. Could you recommend a way to achieve the same effect? @riverpod
class KeepRandomUntil extends _$KeepRandomUntil {
@override
void build() {};
void execute(double endValue) {
final currentValue = ref.watch(randomNumberProvider); // BAD, no watch in non-build function
if (currentValue != endValue) {
ref.read(randomNumberProvider.notifier).randomize();
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is this pattern acceptable, for a provider to trigger another provider which could trigger that provider again until a certain condition is met?
P/s: I haven't tried this on an editor, so excuse me for syntax errors
Beta Was this translation helpful? Give feedback.
All reactions