wagmi
Version:
React Hooks for Ethereum
29 lines (22 loc) • 753 B
text/typescript
'use client'
import {
type GetConnectionsReturnType,
getConnections,
watchConnections,
} from '@wagmi/core'
import { useSyncExternalStore } from 'react'
import type { ConfigParameter } from '../types/properties.js'
import { useConfig } from './useConfig.js'
export type UseConnectionsParameters = ConfigParameter
export type UseConnectionsReturnType = GetConnectionsReturnType
/** https://wagmi.sh/react/api/hooks/useConnections */
export function useConnections(
parameters: UseConnectionsParameters = {},
): UseConnectionsReturnType {
const config = useConfig(parameters)
return useSyncExternalStore(
(onChange) => watchConnections(config, { onChange }),
() => getConnections(config),
() => getConnections(config),
)
}