'use client' import { type Config, type GetConnectionReturnType, getConnection, type ResolvedRegister, watchConnection, } from '@wagmi/core' import type { ConfigParameter } from '@wagmi/core/internal' import { useConfig } from './useConfig.js' import { useSyncExternalStoreWithTracked } from './useSyncExternalStoreWithTracked.js' export type UseConnectionParameters = ConfigParameter export type UseConnectionReturnType = GetConnectionReturnType /** https://wagmi.sh/react/api/hooks/useConnection */ export function useConnection< config extends Config = ResolvedRegister['config'], >( parameters: UseConnectionParameters = {}, ): UseConnectionReturnType { const config = useConfig(parameters) return useSyncExternalStoreWithTracked( (onChange) => watchConnection(config, { onChange }), () => getConnection(config), ) }