watchClient
Subscribe to Client changes.
Import
ts
import { watchClient } from '@wagmi/core'
Usage
ts
import { watchClient } from '@wagmi/core'
import { config } from './config'
const unwatch = watchClient(config, {
onChange(client) {
console.log('Client changed!', client)
},
})
unwatch()
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters
ts
import { type WatchClientParameters } from '@wagmi/core'
onChange
onChange(client: GetClientReturnType, prevClient: GetClientReturnType): void
Callback function called when Client changes.
ts
import { watchClient } from '@wagmi/core'
import { config } from './config'
const unwatch = watchClient(config, {
onChange(client) {
console.log('Client changed!', client)
},
})
unwatch()
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type
ts
import { type WatchClientReturnType } from '@wagmi/core'
Function for cleaning up watcher.