useReads
Runs several reads at once; their RPC calls share the client's multicall batches. Signature, options, result and examples for useReads in @ensforge/react.
Read hookstable
Since v1.0.0View source
Runs several reads at once; their RPC calls share the client's multicall batches.
When to use
Use for a list of reads whose length changes, such as an avatar per row. For a fixed set, separate hooks read just as well.
Signature
function useReads<const reads extends readonly ReadSpec[]>(reads: reads, config: Omit<ReadConfig, "enabled"> = {}): ReadsResult<reads>Examples
import { Actions } from "@ensforge/sdk"
import { useReads } from "@ensforge/react"
function Addresses({ names }: { names: readonly string[] }) {
const results = useReads(names.map((name) => [Actions.record.getAddress, { name }] as const))
return <ul>{results.map((result, index) => <li key={names[index]}>{result.data}</li>)}</ul>
}See also
- The hook types:
ReadResult,WriteResultandReadConfig.
Was this page helpful?