Skip to content

Pass in dynamic callbacks - #26

Draft
joshr4 wants to merge 1 commit into
t4t5:mainfrom
joshr4:modify-event-callback
Draft

Pass in dynamic callbacks#26
joshr4 wants to merge 1 commit into
t4t5:mainfrom
joshr4:modify-event-callback

Conversation

@joshr4

@joshr4 joshr4 commented Aug 11, 2023

Copy link
Copy Markdown

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