Re-using write/simulate hooks generic types #3477
Replies: 1 comment
-
I am dealing with a similar situation where I am trying to make reusable hooks that wrap common functionality and than pass in the A very simple example of how v2 made typings a bit strange/harder is also with with using the While I appreciate the versatility this brings, to me it's usually not the way I am using these hooks as each one is used usually only for a specific contract call (even recommended by the react-query team because if one mutation is reused across multiple things you run into problem with loading states...). But I guess adding a reusable hook that would do that is not hard but than we run into the hassle of the types mentioned above. |
Beta Was this translation helpful? Give feedback.
-
I have a code that I keep repeating over and over for different contract functions write hooks. it consists of
useSimulateContract
and thenuseWriteContract
,useWaitForTransactionReceipt
, and then some extra repetitive code likeconst isLoading = isLoadingReceipt || isLoadingPrepare || isLoadingWrite || isFetchingReceipt;
I am trying to make it into it's own wrapper-hook, where I can pass a
useSimulateContract
config as a generic type, and for this wrapper hook return value to be config (abi, functionName, etc) aware. I might have looked at the code for too longm now, but so far having no luck. Tried different combinations ofUseSimulateContractParameters
as well as Parameters andUseSimulateContractReturnType
to no avail. I'll keep trying to make this work, but was wondering if anyone tried anything similar and had a success.here's a quick example of me trying to make it work https://stackblitz.com/edit/new-wagmi-rzlztm?file=src%2Fuse-wrapped-contract-write.ts
particulary this part
Then when trying to pass such config to
useSimulateContract
,args
are incompatible for exampleBeta Was this translation helpful? Give feedback.
All reactions