Replies: 3 comments 3 replies
-
import { useContractRead, erc20ABI } from 'wagmi'
useContractRead({
address: '0x',
abi: erc20ABI,
functionName: 'balanceOf',
args: ['0x'],
// ^? (property) args?: readonly [`0x${string}`] | undefined
}).data |
Beta Was this translation helpful? Give feedback.
1 reply
-
The arguments array can be undefined, yes My suggestion is to allow elements of the array be undefined - and, if undefined, don't run the hook. |
Beta Was this translation helpful? Give feedback.
2 replies
-
I don't know your codebase well enough to do a PR, but here's some code for a starting point, if it's helpful anyMissingArgs.ts:
useContractRead.ts:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider this scenario:
We're trying to 1) Load a user's address and 2) Load some data based on the user's address
But this won't work, because
args
is of type0x${string}
anduserAddress
may be undefined until it loads.One workaround:
But that's wonky
Instead, what if
useContractRead
allowed arguments to beundefined
and simply did not execute if an undefined argument was passed (similar to ifaddress
is missing)This is an example implementation:
Also: I've found myself implementing convenience hooks for these other two scenarios as well:
^-- to work around two limitations: 1) the missing arguments, as mentioned above ... and 2) the fact that if anything is missing in
useContractReads
contracts array, the entire hook won't runBeta Was this translation helpful? Give feedback.
All reactions