-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Using useFuture and useStream keeps invoking the widget build method unnecessarily. #418
Comments
Sounds like you are recreating the Future/Stream in every build. What you need to do is cache it between builds, with a useMemoized for example final future = useMemoized(() => api.fetch(), []);
final snap = useFuture(future);
... |
Please share a complete example. Otherwise I can only assume that this is your mistake |
|
Indeed, like mentioned by David above, you need to cache your Future/Stream in a useMemoized if you want to do that. If the future/stream passed to useFuture/useStream changes, they start listening to it. So you re-enter a "loading" cycle. It's not a hooks bug :) |
This is nonintuitive. Also, useStream documentation doesn't mention/recommend using useMemoized. This can create unexpected bugs and/or suboptimal performance for users. For me, using useMemoized with useFuture/useStream is not an acceptable solution. Anyways, thank you for your response. |
Steps,
You will notice that the widget build method is invoked several times a second without any updates from Future or Stream.
The text was updated successfully, but these errors were encountered: