useAccountEffect
Hook for listening to account lifecycle events.
Import
import { useAccountEffect } from "starkweb/react"
Usage
index.tsx
import { useAccountEffect } from "starkweb/react"
function App() {
useAccountEffect({
onConnect(data) {
console.log("Connected!", data)
},
onDisconnect() {
console.log("Disconnected!")
},
})
}
Parameters
import { type UseAccountEffectParameters } from "starkweb/react"
config
Config | undefined
Config
to use instead of retrieving from the nearest StarkwebProvider
.
index.tsx
import { useAccountEffect } from "starkweb/react"
import { config } from "./config"
function App() {
useAccountEffect({
config,
onConnect(data) {
console.log("Connected!", data)
},
onDisconnect() {
console.log("Disconnected!")
},
})
}
onConnect
((data: { address: `0x${string}`; addresses: readonly [`0x${string}`, ...`0x${string}`[]]; chain: Chain | undefined; chainId: number; connector: Connector; isReconnected: boolean }) => void) | undefined
Callback that is called when accounts are connected.
index.tsx
import { useAccountEffect } from "starkweb/react"
function App() {
useAccountEffect({
onConnect(data) {
console.log("Connected!", data)
},
})
}
onDisconnect
(() => void) | undefined
Callback that is called when no more accounts are connected.
index.tsx
import { useAccountEffect } from "starkweb/react"
function App() {
useAccountEffect({
onDisconnect() {
console.log("Disconnected!")
},
})
}