Skip to content

useAgentState

useAgentState provides access to the agent’s initialization state and network information.

import { useAgentState } from "./reactor/hooks"
function AgentStatus() {
const {
isInitialized, // Agent is ready
isInitializing, // Agent is starting up
isLocalhost, // Connected to local network
network, // "ic" | "local"
error, // Error | undefined
} = useAgentState()
if (isInitializing) return <div>Connecting...</div>
return <div>Connected to {network}</div>
}
PropertyTypeDescription
isInitializedbooleanWhether the agent has finished initializing
isInitializingbooleanWhether the agent is currently initializing
isLocalhostbooleanWhether the agent is connected to a local development network
network"ic" | "local"The network the agent is connected to
errorError | undefinedAny error that occurred during initialization
import { useAgentState } from "./reactor/hooks"
function App({ children }) {
const { isInitializing, error } = useAgentState()
if (isInitializing) {
return <div className="loading">Initializing Agent...</div>
}
if (error) {
return <div className="error">Failed to connect: {error.message}</div>
}
return children
}