I think Wagmi uses react-query
under the hood. So I want to refresh queries whenever and wherever I wanted using invalidateQueries
method like we use to do with react-query
.
Here is the query that I want to refetch:
import { useContractRead } from 'wagmi';
const balance = useContractRead({
address: --random-adress--,
abi: random.abi,
functionName: 'balanceOf',
onSuccess: () => {
console.log('balanceOf refeched');
},
cacheTime: 0,
staleTime: 0,
scopeKey: 'balanceOf',
});
And here is the implementation of invalidation:
import { useQueryClient } from 'wagmi';
function App() {
const queryClient = useQueryClient();
return (
<button
onClick={() => {
queryClient.invalidateQueries({ queryKey: ['balanceOf'] });
}}
>
Click Me!
</button>
);
}
export default App;
First I thought the function name is also query key but it's not worked. Then I added scopeKey hoping it would be the queryKey but it still not works.
Version: wagmi@1.^*