Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 4ef47ee

Browse files
authored
fix useContractCall hook (#119)
* fix useContractCall hook * v2.6.1-0
1 parent 2e7d62c commit 4ef47ee

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

docs/react.usecontractcall.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Use this to get a function to make a write call to your contract
1212
<b>Signature:</b>
1313

1414
```typescript
15-
export declare function useContractCall(contract: RequiredParam<ReturnType<typeof useContract>["contract"]>, functionName: RequiredParam<string>): import("@tanstack/react-query").UseMutationResult<any, unknown, unknown, unknown>;
15+
export declare function useContractCall(contract: RequiredParam<ReturnType<typeof useContract>["contract"]>, functionName: RequiredParam<string>): import("@tanstack/react-query").UseMutationResult<any, unknown, unknown[] | [...unknown[], CallOverrides] | undefined, unknown>;
1616
```
1717

1818
## Parameters
@@ -24,7 +24,7 @@ export declare function useContractCall(contract: RequiredParam<ReturnType<typeo
2424

2525
<b>Returns:</b>
2626

27-
import("@tanstack/react-query").UseMutationResult&lt;any, unknown, unknown, unknown&gt;
27+
import("@tanstack/react-query").UseMutationResult&lt;any, unknown, unknown\[\] \| \[...unknown\[\], CallOverrides\] \| undefined, unknown&gt;
2828

2929
a response object that includes the write function to call
3030

@@ -36,6 +36,6 @@ const { contract } = useContract("{{contract_address}}");
3636
const { mutate: myFunction, isLoading, error } = useContractCall(contract, "myFunction");
3737

3838
// the function can be called as follows:
39-
// myFunction(...args)
39+
// myFunction(["param 1", "param 2", ...])
4040
```
4141

docs/snippets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"name": "useContractCall",
41-
"example": "const { contract } = useContract(\"{{contract_address}}\");\nconst { mutate: myFunction, isLoading, error } = useContractCall(contract, \"myFunction\");\n\n// the function can be called as follows:\n// myFunction(...args)",
41+
"example": "const { contract } = useContract(\"{{contract_address}}\");\nconst { mutate: myFunction, isLoading, error } = useContractCall(contract, \"myFunction\");\n\n// the function can be called as follows:\n// myFunction([\"param 1\", \"param 2\", ...])",
4242
"reference": "https://portal.thirdweb.com/react/react.usecontractcall"
4343
},
4444
{

etc/react.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ export function useContractAbi(contractAddress: RequiredParam<ContractAddress>):
12551255
};
12561256

12571257
// @beta
1258-
export function useContractCall(contract: RequiredParam<ReturnType<typeof useContract>["contract"]>, functionName: RequiredParam<string>): UseMutationResult<any, unknown, unknown, unknown>;
1258+
export function useContractCall(contract: RequiredParam<ReturnType<typeof useContract>["contract"]>, functionName: RequiredParam<string>): UseMutationResult<any, unknown, unknown[] | [...unknown[], CallOverrides] | undefined, unknown>;
12591259

12601260
// @beta
12611261
export function useContractCompilerMetadata(contractAddress: RequiredParam<ContractAddress>): UseQueryResult< {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thirdweb-dev/react",
3-
"version": "2.6.0",
3+
"version": "2.6.1-0",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com:thirdweb-dev/react.git"

src/hooks/async/contracts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export function useContractData(
409409
* const { mutate: myFunction, isLoading, error } = useContractCall(contract, "myFunction");
410410
*
411411
* // the function can be called as follows:
412-
* // myFunction(...args)
412+
* // myFunction(["param 1", "param 2", ...])
413413
*```
414414
*
415415
* @param contract - the contract instance of the contract to call a function on
@@ -427,13 +427,13 @@ export function useContractCall(
427427
const queryClient = useQueryClient();
428428

429429
return useMutation(
430-
async (...args: unknown[] | [...unknown[], CallOverrides]) => {
430+
async (callParams?: unknown[] | [...unknown[], CallOverrides]) => {
431431
invariant(contract, "contract must be defined");
432432
invariant(functionName, "function name must be provided");
433-
if (!args.length) {
433+
if (!callParams?.length) {
434434
return contract.call(functionName);
435435
}
436-
return contract.call(functionName, ...args);
436+
return contract.call(functionName, ...callParams);
437437
},
438438
{
439439
onSettled: () =>

0 commit comments

Comments
 (0)