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

Fetch resources on load for React hooks instead of asking devs to call it in a useEffect #116

Open
Tbaut opened this issue Jan 10, 2025 · 0 comments
Labels
Type: Enhancement Added to issues and PRs when a change includes improvements or optimizations.

Comments

@Tbaut
Copy link
Collaborator

Tbaut commented Jan 10, 2025

For useSprinterTokens, useSprinterChains and useSprinterBalances, we request users to call a corresponding getter function such as getUserBalances in a useEffect.

I'd propose to remove this, or to call it refresh, and to actually call the relevant function right on load.

e.g users could have:

const { balances, error, isLoading, refresh } = useSprinterBalances('0x123..')

if (isLoading) return <Loader />
if (!!error) return <div>Something went wrong {error}<div>

return <div>balances.length</div>

on address change (in useSprinterBalances), the balances would be refetched, and if the users for some reason want to programmatically refresh, they can call the refresh.

This is more in line with the hooks I'm used to use. WDYT @BeroBurny @saadahmsiddiqui ?

@Tbaut Tbaut added the Type: Enhancement Added to issues and PRs when a change includes improvements or optimizations. label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Added to issues and PRs when a change includes improvements or optimizations.
Projects
None yet
Development

No branches or pull requests

1 participant