-
-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Labels
Description
Describe the bug
When the callback reference is updated, the useOnStreamChange
hook doesn't update.
final onDataCallback = useCallback((int data) {
print(multiplierValue * data);
}, [multiplierValue]); // dependency triggers a callback ref change
useOnStreamChange(stream, onData: onDataCallback);
Cause:
flutter_hooks/packages/flutter_hooks/lib/src/async.dart
Lines 396 to 397 in 319679b
if (oldWidget.stream != hook.stream || | |
oldWidget.cancelOnError != hook.cancelOnError) { |
The hook implementation only check for changes of stream
and cancelOnError
parameters, other callback parameters are ignored.
To Reproduce
Reproducible sample: https://dartpad.dev/?id=cdc8f5006a2e15f0761504cba0ab81cb
Expected behavior
When the callback reference is updated, the hook should _unsubscribe()
and _subscribe()
again to update the callback reference; or use some kind of callback wrapper to always provide the latest callback reference (doesn't work).
I can also provide the PR if this behavior is indeed a bug.
benthillerkus