You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: site/react/guides/read-from-contract.md
+54
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,60 @@ function ReadContract() {
70
70
}
71
71
```
72
72
73
+
## Refetching On Blocks
74
+
75
+
The [`useBlockNumber` Hook](/react/api/hooks/useBlockNumber) can be utilized to refetch or [invalidate](https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation) the contract data on a specific block interval.
Copy file name to clipboardexpand all lines: site/vue/guides/read-from-contract.md
+56
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,62 @@ const {
75
75
76
76
:::
77
77
78
+
<!-- TODO: ## Refetching On Blocks
79
+
80
+
The [`useBlockNumber` Hook](/react/api/hooks/useBlockNumber) can be utilized to refetch or [invalidate](https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation) the contract data on a specific block interval.
81
+
82
+
:::code-group
83
+
```tsx [read-contract.tsx (refetch)]
84
+
import { useEffect } from 'react'
85
+
import { useBlockNumber, useReadContract } from 'wagmi'
// if `useReadContract` is in a different hook/component,
122
+
// you can import `readContractQueryKey` from `'wagmi/query'` and
123
+
// construct a one-off query key to use for invalidation
124
+
queryClient.invalidateQueries({ queryKey })
125
+
}, [blockNumber, queryClient])
126
+
127
+
return (
128
+
<div>Balance: {balance?.toString()}</div>
129
+
)
130
+
}
131
+
```
132
+
::: -->
133
+
78
134
<!-- TODO: ## Calling Multiple Functions
79
135
80
136
We can use the [`useReadContract` Hook](/react/api/hooks/useReadContract) multiple times in a single component to call multiple functions on the same contract, but this ends up being hard to manage as the number of functions increases, especially when we also want to deal with loading & error states.
0 commit comments