Skip to content
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

useOnStreamChange doesn't update on callback changes #451

Open
arkare opened this issue Dec 22, 2024 · 0 comments
Open

useOnStreamChange doesn't update on callback changes #451

arkare opened this issue Dec 22, 2024 · 0 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@arkare
Copy link

arkare commented Dec 22, 2024

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.

@arkare arkare added bug Something isn't working needs triage labels Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants