Skip to content

Conversation

@mikerowehl
Copy link
Contributor

Description

I mostly followed the recipe for reading from a contract in the Scaffold docs. However, when I used the public Arbitrum network I was getting pretty long periods where I would get the default value displayed, and then it would display the spinner, and then display the actual value. I haven't used Wagmi and TanStack too much before, but it appears isLoading only covers when the request is literally inflight - so not the period before when the query is issued and other state is being setup. At least that was my take away from this discussion in the TanStack issues about isLoading vs isPending

And even with isPending it only covers the success case. If I swapped to isPending and handled the rest the same the page would incorrectly show 0 check-ins if there was an error. So instead I used the Wagmi versions and check for isSuccess instead. If there's an error it now just leaves the spinner forever. But I felt that was more accurate than letting it default to 0.

Additional Information

Related Issues

Closes #7

Your ENS/address: mikerowehl.eth (0x9c9234420501c820f73cfA44e822D27e1baAb4D5)

@vercel
Copy link

vercel bot commented Dec 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
batch22.buidlguidl.com Ready Ready Preview Comment Dec 3, 2025 9:45pm

import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
const { data: checkedInCounter, isSuccess: isCheckedInCounterSuccess } = useScaffoldReadContract({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Mike, your solution works, but is there a particular reason to use isSuccess instead of isLoading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I put some details in the PR description. But the sort version is that for TanStack at least, isLoading covers only when the network request is running, and can miss initialization before the request. I initially did it just like the recipe from the Scaffold docs, but I was getting a "0" displayed, then a loading spinner, and then the number. So I swapped to the Wagmi isSuccess instead to only show the value once the request is done and if there are no errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks

@melanke melanke merged commit 541d1fc into BuidlGuidl:main Dec 5, 2025
3 checks passed
@mikerowehl mikerowehl deleted the check-in-counter branch December 5, 2025 13:14
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.

e) Get the check-in count from the BatchRegistry contract

2 participants