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

Pass in dynamic callbacks #26

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

joshr4
Copy link

@joshr4 joshr4 commented Aug 11, 2023

I was attempting to use the onEvent callback of the useNostrEvents hook, and ran into an issue where the callback cannot be updated. This was problematic, as my callback depended on my component's state, which changed over time. I successfully registered the callback, but as the callback was redefined on each render cycle, the useNostrEvents hook continued to use the initial callback that was referencing stale data.

The solution I came up with was to monitor the events array returned by useNostrEvents, and execute my callback on each new event that came in. Another approach that may work here is to allow the callback to be dynamically updated. This PR makes a change that may facilitate that.

I still need to test out this change to verify it is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant