@macalinao/grill
Version:
Modern Solana development kit for React applications with automatic account batching, caching, and transaction notifications
37 lines • 1.12 kB
JavaScript
import { useAccount } from "./use-account.js";
/**
* 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
*
* @example
* ```tsx
* import { createDecodedAccountHook } from "@macalinao/grill";
* import { getPoolDecoder } from "@macalinao/clients-meteora-damm-v2";
*
* const usePool = createDecodedAccountHook(getPoolDecoder());
*
* function PoolDisplay({ address }: { address: Address }) {
* // Basic usage
* const { data: pool } = usePool({ address });
*
* // With real-time updates
* const { data: livePool } = usePool({
* address,
* subscribeToUpdates: true,
* });
*
* return <div>{pool?.data.liquidity.toString()}</div>;
* }
* ```
*/
export function createDecodedAccountHook(decoder) {
return function useDecodedAccount({ address, subscribeToUpdates, }) {
return useAccount({
address,
decoder,
subscribeToUpdates,
});
};
}
//# sourceMappingURL=create-decoded-account-hook.js.map