Skip to content

useOnStreamChange doesn't update on callback changes #451

@arkare

Description

@arkare

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:

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions