UNPKG

@macalinao/grill

Version:

Modern Solana development kit for React applications with automatic account batching, caching, and transaction notifications

35 lines (32 loc) 1.01 kB
import type { Account, Address, Decoder } from "@solana/kit"; import type { UseQueryResult } from "@tanstack/react-query"; import { useAccount } from "./use-account.js"; /** * A hook for fetching and decoding accounts. */ export type UseDecodedAccountHook<TData extends object> = (args: { address: Address | null | undefined; }) => UseQueryResult<Account<TData> | null> & { address: Address | null | undefined; }; /** * Generic helper to create a hook for fetching and decoding accounts * @param decoder - The decoder to use for the account data * @returns A hook function that fetches and decodes the account */ export function createDecodedAccountHook<TData extends object>( decoder: Decoder<TData>, ): UseDecodedAccountHook<TData> { return function useDecodedAccount({ address, }: { address: Address | null | undefined; }): UseQueryResult<Account<TData> | null> & { address: Address | null | undefined; } { return useAccount({ address, decoder, }); }; }