@macalinao/grill
Version:
Modern Solana development kit for React applications with automatic account batching, caching, and transaction notifications
23 lines • 973 B
JavaScript
import { useQuery } from "@tanstack/react-query";
import { useGrillContext } from "../contexts/grill-context.js";
import { createAccountQueryKey, fetchAndDecodeAccount, } from "../utils/account-helpers.js";
/**
* Get the account info for an address. Concurrent queries are batched using a DataLoader.
*/
export function useAccount({ options, address, decoder, }) {
const { accountLoader } = useGrillContext();
// TODO(igm): improve the types here and somehow ensure the decoder is the same
// for each query of an account
return {
...useQuery({
networkMode: "offlineFirst",
...options,
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: address ? createAccountQueryKey(address) : [null],
queryFn: () => fetchAndDecodeAccount(address, accountLoader, decoder),
enabled: !!address,
}),
address,
};
}
//# sourceMappingURL=use-account.js.map