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" | "remote" | undefined error, // Error | undefined } = useAgentState()
if (isInitializing) return <div>Connecting...</div> return <div>Connected to {network}</div>}Return Value
Section titled “Return Value”| Property | Type | Description |
|---|---|---|
isInitialized |
boolean |
Whether the agent has finished initializing |
isInitializing |
boolean |
Whether the agent is currently initializing |
isLocalhost |
boolean |
Whether the agent is connected to a local development network |
network |
string | undefined |
The network the agent is connected to — "ic", "local", or "remote" (Codespaces/Gitpod) |
error |
Error | undefined |
Any error that occurred during initialization |
Examples
Section titled “Examples”Initial Loading Screen
Section titled “Initial Loading Screen”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}See Also
Section titled “See Also”- createAuthHooks — Auth hooks factory
- useAuth — Main auth hook