Skip to content

Commit

Permalink
docs: close #4344
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Nov 5, 2024
1 parent ecac0ba commit 254f8f7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
8 changes: 4 additions & 4 deletions site/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ export function getSidebar() {
text: 'useInfiniteReadContracts',
link: '/react/api/hooks/useInfiniteReadContracts',
},
{
text: 'useReadContract',
link: '/react/api/hooks/useReadContract',
},
{
text: 'usePrepareTransactionRequest',
link: '/react/api/hooks/usePrepareTransactionRequest',
},
{
text: 'useReadContract',
link: '/react/api/hooks/useReadContract',
},
{
text: 'useReadContracts',
link: '/react/api/hooks/useReadContracts',
Expand Down
15 changes: 13 additions & 2 deletions site/react/guides/read-from-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The [`useReadContract` Hook](/react/api/hooks/useReadContract) allows you to rea
The component below shows how to retrieve the token balance of an address from the [Wagmi Example](https://etherscan.io/token/0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2) contract

:::code-group

```tsx [read-contract.tsx]
import { useReadContract } from 'wagmi'

Expand All @@ -21,9 +20,21 @@ function ReadContract() {
)
}
```

:::

If `useReadContract` depends on another value (`address` in the example below), you can use the [`query.enabled`](http://localhost:5173/react/api/hooks/useReadContract#enabled) option to prevent the query from running until the dependency is ready.

```tsx
const { data: balance } = useReadContract({
...wagmiContractConfig,
functionName: 'balanceOf',
args: [address],
query: { // [!code focus]
enabled: !!address, // [!code focus]
}, // [!code focus]
})
```

## Loading & Error States

The [`useReadContract` Hook](/react/api/hooks/useReadContract) also returns loading & error states, which can be used to display a loading indicator while the data is being fetched, or an error message if contract execution reverts.
Expand Down
15 changes: 15 additions & 0 deletions site/vue/guides/read-from-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ const { data: balance } = useReadContract({

:::


If `useReadContract` depends on another value (`address` in the example below), you can use the [`query.enabled`](http://localhost:5173/vue/api/composables/useReadContract#enabled) option to prevent the query from running until the dependency is ready.

```tsx
const { data: balance } = useReadContract({
...wagmiContractConfig,
functionName: 'balanceOf',
args: [address],
query: { // [!code focus]
enabled: !!address, // [!code focus]
}, // [!code focus]
})
```


## Loading & Error States

The [`useReadContract` Composable](/vue/api/composables/useReadContract) also returns loading & error states, which can be used to display a loading indicator while the data is being fetched, or an error message if contract execution reverts.
Expand Down

0 comments on commit 254f8f7

Please sign in to comment.