question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: useContractRead fetching data automatically with enabled set to false

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.6.4

Current Behavior

useContractRead is fetching data automatically with enabled set to false and isLoading and isFetching are showing false.

const {
    data: readData,
    isLoading: isReadLoading,
    isFetching: isReadFetching,
    refetch
  } = useContractRead({
    addressOrName: "0xecb504d39723b0be0e3a9aa33d646642d1051ee1",
    contractInterface: wagmigotchiABI,
    functionName: "getBoredom",
    enabled: false
  });

  console.log({ isReadFetching });
  console.log({ isReadLoading });
  console.log("Result from read:", readData);

Expected Behavior

Fetching contract data on load shouldn’t happen if enabled is set to false. Also, when fetching data, isFetching (possibly isLoading too) should have true value.

Steps To Reproduce

Open codesandbox link and watch the Console.

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

https://codesandbox.io/s/condescending-allen-ek1ion?file=/pages/index.tsx

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
tmmcommented, Oct 14, 2022

@rsodre for some quick hints check out React Query’s definition of network states. There are a couple nuances with wagmi’s set up, but overall it’s pretty much the same.

The watch configuration option listens for new blocks (via polling or websockets) and refetches the data. cacheOnBlock is similar. It also listens for new blocks, but also uses current block number as part of the cache key.

Agree that we need to improve the docs and appreciate the feedback!

0reactions
rsodrecommented, Oct 13, 2022

I’m having a similar issue, I know data is cached, chain block did not change (using local Ganache), then useContractRead returns status:success, but isFetching:true. It takes a couple of seconds before isFetching is released (the same time my function takes to complete). Is it calling the function even when the cache is ok, ‘just in case’?

I usually consider (isLoading || isFetching) to block UI until data is available. In this case, if I just ignore isFetching, cached data comes quickly. So, can I just completely ignore isFetching?

I just ported my dapp from Moralis to wagmi, in favour of a completely open source, and to benefit from caching, but I’m still lost on what’s happening under the hood, and would be really grateful if some concepts were better explained on the docs, like how exactly does caching work? What’s the difference between loading and fetching? What is stale data? What’s the difference between cacheOnBlock and watch?

Read more comments on GitHub >

github_iconTop Results From Across the Web

useContractRead - Wagmi
enabled (optional). Set this to false to disable this query from automatically running. Defaults to true . import { useContractRead } from 'wagmi'...
Read more >
Complete guide to RainbowKit and Wagmi for your frontend
A guide about going from Hardhat, to deploying and verifying to connecting it to the frontend with Rainbow and Wagmi.
Read more >
Build an NFT Minting Page with thirdweb, IPFS, RainbowKit ...
Learn how to build an NFT minting page with thirdweb, IPFS, RainbowKit & WAGMI.
Read more >
On Ethereum developer experience - by Slava Akhmechet
It's simply too easy to introduce security bugs, and much of this ... automatically find out your client is now wrong, no autocomplete,...
Read more >
ethers-react | react module is built to increase developer velocity
Implement ethers-react with how-to, Q&A, fixes, code snippets. kandi ratings - Low support, No Bugs, No Vulnerabilities. Permissive License, Build not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found