@wagmi/vue
Version:
Vue Composables for Ethereum
31 lines (24 loc) • 865 B
text/typescript
import {
type GetConnectionsReturnType,
getConnections,
watchConnections,
} from '@wagmi/core'
import { onScopeDispose, type Ref, readonly, ref } from 'vue'
import type { ConfigParameter } from '../types/properties.js'
import { useConfig } from './useConfig.js'
export type UseConnectionsParameters = ConfigParameter
export type UseConnectionsReturnType = Ref<GetConnectionsReturnType>
/** https://wagmi.sh/vue/api/composables/useConnections */
export function useConnections(
parameters: UseConnectionsParameters = {},
): UseConnectionsReturnType {
const config = useConfig(parameters)
const connections = ref(getConnections(config))
const unsubscribe = watchConnections(config, {
onChange(data) {
connections.value = data
},
})
onScopeDispose(() => unsubscribe())
return readonly(connections) as UseConnectionsReturnType
}