bug: useContractRead fetching data automatically with enabled set to false
See original GitHub issueIs 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:
- Created a year ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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!
I’m having a similar issue, I know data is cached, chain block did not change (using local Ganache), then
useContractRead
returnsstatus:success
, butisFetching:true
. It takes a couple of seconds beforeisFetching
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 ignoreisFetching
, cached data comes quickly. So, can I just completely ignoreisFetching
?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?