-
Notifications
You must be signed in to change notification settings - Fork 809
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
Add requiredFilters param to useScaffoldEventHistory hook #621
Conversation
what about adding why it can be so your hook will look like const { roomHash } = router.query as { roomHash: 0x${string} };
const {
data: roomJoinEvents,
isLoading: isLoadingRoomCreateEvents,
error: errorReadingRoomCreateEvents,
} = useScaffoldEventHistory({
contractName: "BettingRoom",
eventName: "RoomJoin",
fromBlock: 1n,
filters: { roomHash: roomHash },
watch: true,
enabled: Boolean(roomHash)
}); |
Thanks for the feedback! I think this is a good option too! Not sure what is better ;-) roomHash is undefined before it's hydrated with the router query data. |
I like the |
Thanks @damianmarti for making the hooks better. And thanks all for the review!!! |
Description
Add requiredFilters param to useScaffoldEventHistory hook to avoid getting wrong events when setting a filter that is not yet populated with the right value.
If one of the requiredFilters is not set, the hook returns an error.
For example, if I get the filter value from the router query, the first value is undefined, and the hook will return all the events, without this filter applied.
To fix it, I can use a useEffect hook, something like this:
But if I use the requieredFilters params I only need the useScaffoldEventHistory hook:
Or maybe there is another better option that I'm missing :-)
Additional Information
Your ENS/address: damianmarti.eth