Function AgentProvider

  • AgentProvider is a React functional component that serves as a context provider for IC agent and authentication hooks. It enables any child components to access and use the agent and authentication functionalities seamlessly.

    The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to create various hooks related to agent operations and authentication processes. These hooks are made available to all child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.

    Parameters

    Returns ReactNode

    Example

    Wrap your App with AgentProvider to provide all child components access to IC agent and authentication hooks.

    <AgentProvider>
    <App />
    </AgentProvider>

    Inside App or any of its children, you can use the hooks provided through the context to interact with the IC, manage authentication, and perform other agent-related tasks.

Properties

propTypes?: WeakValidationMap<AgentProviderProps>

Used to declare the types of the props accepted by the component. These types will be checked during rendering and in development only.

We recommend using TypeScript instead of checking prop types at runtime.

contextTypes?: ValidationMap<any>

Deprecated

Lets you specify which legacy context is consumed by this component.

See

Legacy React Docs

defaultProps?: Partial<AgentProviderProps>

Used to define default values for the props accepted by the component.

See

React Docs

Example

type Props = { name?: string }

const MyComponent: FC<Props> = (props) => {
return <div>{props.name}</div>
}

MyComponent.defaultProps = {
name: 'John Doe'
}
displayName?: string

Used in debugging messages. You might want to set it explicitly if you want to display a different name for debugging purposes.

See

Legacy React Docs

Example


const MyComponent: FC = () => {
return <div>Hello!</div>
}

MyComponent.displayName = 'MyAwesomeComponent'