'use client' import { type Config, type GetChainIdReturnType, getChainId, type ResolvedRegister, watchChainId, } from '@wagmi/core' import type { ConfigParameter } from '@wagmi/core/internal' import { useSyncExternalStore } from 'react' import { useConfig } from './useConfig.js' export type UseChainIdParameters = ConfigParameter export type UseChainIdReturnType = GetChainIdReturnType /** https://wagmi.sh/react/api/hooks/useChainId */ export function useChainId( parameters: UseChainIdParameters = {}, ): UseChainIdReturnType { const config = useConfig(parameters) return useSyncExternalStore( (onChange) => watchChainId(config, { onChange }), () => getChainId(config), () => getChainId(config), ) }