hyperweb-io / hyperweb-io/telescope
React Query hooks code possibly can be more simplified
- Dominant language
- TypeScript
- Stars
- 154
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Hi, June proposed that React Query hooks code possibly can be more simplified.
```
const rpcEndpoint = 'https://rpc.cosmos.directory/cosmoshub';
const { data: rpcClient } = useRpcClient({
rpcEndpoint,
options: {
enabled: !!rpcEndpoint,
},
});
//@ts-ignore
// const cosmosHooks = cosmos.ClientFactory.createRPCQueryHooks({ rpc: rpcClient })
const cosmosHooks = createRpcQueryHooks({ rpc: rpcClient });
const {
data: balance,
isSuccess: isBalanceLoaded,
isLoading: isFetchingBalance,
refetch: refetchBalance,
} = cosmosHooks.cosmos.bank.v1beta1.useBalance({
request: {
address: address || '',
denom: chainassets?.assets[0].base as string,
},
options: {
enabled: !!address && !!rpcClient,
// transform the returned balance into a BigNumber
select: ({ balance }) =>
new BigNumber(balance?.amount ?? 0).multipliedBy(
10 ** -COIN_DISPLAY_EXPONENT
),
},
});
```
Can we make this code less like:
```
const cosmosHooks = createRpcQueryHooks({ url: "https://rpc.cosmos.directory/cosmoshub" });
const {
data: balance,
isSuccess: isBalanceLoaded,
isLoading: isFetchingBalance,
refetch: refetchBalance,
} = cosmosHooks.cosmos.bank.v1beta1.useBalance({
request: {
address: address || '',
denom: chainassets?.assets[0].base as string,
},
options: {
enabled: !!address && !!rpcClient,
// transform the returned balance into a BigNumber
select: ({ balance }) =>
new BigNumber(balance?.amount ?? 0).multipliedBy(
10 ** -COIN_DISPLAY_EXPONENT
),
},
});
```
It needs createRpcQueryHooks also accepting url optionally to create RPC client by default.
We discuss the logic here.
Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.