Function ActorHookProvider

  • ActorHookProvider is a React functional component that serves as a context provider for IC actor hooks within a React application. It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided actor hooks and configuration.

    Props:

    • hooks: ActorHooksReturnType - The actor hooks object containing the various actor interaction hooks.
    • children: React Node - The child components that will have access to the actor hooks context.

    Behavior:

    • Validates the presence of the hooks object. Throws an error if it is missing, ensuring that the actor hooks are always available for actor operations.
    • Utilizes useMemo to memoize the hooks object, optimizing for performance by avoiding unnecessary recalculations.
    • Renders the child components once the hooks object is available, effectively providing them access to the actor hooks context.

    Parameters

    Returns ReactNode

    Example

    <ActorHookProvider hooks={yourActorHooks}>
    <YourComponent />
    </ActorHookProvider>

    This setup ensures that YourComponent and any of its children can interact with the specified IC actor hooks through the context provided by ActorHookProvider.

Properties

propTypes?: WeakValidationMap<ActorHookProviderProps<types.BaseActor>>

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

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'
}

Deprecated

Use values for destructuring assignments instead.

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'