ic-reactor
    Preparing search index...

    Function createReactor

    • Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application. It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.

      Type Parameters

      Parameters

      • config: types.CreateReactorStoreParameters

        Configuration CreateReactorParameters for the reactor, including:

        • withProcessEnv (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
        • withLocalEnv (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
        • port (optional): Port number for the local or development environment.

      Returns CreateReactorReturnType<A>

      An object containing CreateReactorReturnType hooks and utilities:

      • getAgent - Returns the current agent instance.
      • getVisitFunction - Returns the visit function for the actor.
      • useQueryCall - A hook for querying actor methods.
      • useUpdateCall - A hook for updating actor methods.
      • useAuth - A hook for managing authentication and user principal.
      • useActor - A hook for managing actors and their methods.
      • useActorManager - A hook for managing actor manager and its methods.
      • useAgentManager - A hook for managing agent manager and its methods.
      • initialize - A function to initialize the actor manager if not initialized.
      • useActorState - A hook for managing actor state.
      • useAgent - A hook for managing agent and its methods.
      • useAuthState - A hook for managing authentication state.
      • useAgentState - A hook for managing agent state.
      • useUserPrincipal - A hook for managing user principal.
      • useVisitMethod - A hook for visiting actor methods.
      import { createReactor } from "@ic-reactor/react";
      import type { CreateReactorParameters } from "@ic-reactor/react/dist/types";
      import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"

      const config: CreateReactorParameters = {
      canisterId,
      idlFactory,
      host: "https://localhost:8000", // IC network host |
      withLocalEnv: true, // Set true for local network | one of these
      withProcessEnv: true, // Use process.env to determine host |
      port: 8000, // Port number for local network
      };

      export type YourActor = typeof yourActor;

      export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
      // Now you can use the returned hooks in your React components