Skip to content

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

@Tbaut

Description

@Tbaut

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: EnhancementAdded to issues and PRs when a change includes improvements or optimizations.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions