useContractQuery
Making a query to a registered contract. This hook manages the state of a contract query, including loading state, query results, and error handling. It automatically fetches data when the contract, function, or arguments change.
// ...
import { useContract, useContractQuery } from 'typink';
import { ContractId } from 'contracts/deployments';
import { GreeterContractApi } from 'contracts/types/greeter';
const { contract } = useContract<GreeterContractApi>(ContractId.GREETER);
const {
data: greet,
isLoading,
refresh,
} = useContractQuery({
contract,
fn: 'greet',
});
// ...
Watch for changes
To automatically monitor updates in the contract storage, set the watch
property to true.
// ...
const {
data: greet,
isLoading,
refresh,
watch: true
} = useContractQuery({
contract,
fn: 'greet',
});
// ...
Last updated
Was this helpful?