UNPKG

wagmi

Version:

React Hooks for Ethereum

33 lines 1.3 kB
'use client'; import { useQueryClient } from '@tanstack/react-query'; import { getBlockNumberQueryOptions, } from '@wagmi/core/query'; import { useQuery } from '../utils/query.js'; import { useChainId } from './useChainId.js'; import { useConfig } from './useConfig.js'; import { useWatchBlockNumber, } from './useWatchBlockNumber.js'; /** https://wagmi.sh/react/api/hooks/useBlockNumber */ export function useBlockNumber(parameters = {}) { const config = useConfig(parameters); const chainId = useChainId({ config }); const options = getBlockNumberQueryOptions(config, { ...parameters, chainId: parameters.chainId ?? chainId, }); const queryClient = useQueryClient(); useWatchBlockNumber({ ...{ config: parameters.config, chainId: parameters.chainId, ...(typeof parameters.watch === 'object' ? parameters.watch : {}), }, enabled: Boolean((options.enabled ?? true) && (typeof parameters.watch === 'object' ? parameters.watch.enabled : parameters.watch)), onBlockNumber(blockNumber) { queryClient.setQueryData(options.queryKey, blockNumber); }, }); return useQuery(options); } //# sourceMappingURL=useBlockNumber.js.map