Optional
context: any<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
.
Optional
propUsed 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.
Optional
contextOptional
defaultUsed to define default values for the props accepted by the component.
type Props = { name?: string }
const MyComponent: FC<Props> = (props) => {
return <div>{props.name}</div>
}
MyComponent.defaultProps = {
name: 'John Doe'
}
Optional
displayUsed in debugging messages. You might want to set it explicitly if you want to display a different name for debugging purposes.
const MyComponent: FC = () => {
return <div>Hello!</div>
}
MyComponent.displayName = 'MyAwesomeComponent'
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:
hooks
object. Throws an error if it is missing, ensuring that the actor hooks are always available for actor operations.useMemo
to memoize thehooks
object, optimizing for performance by avoiding unnecessary recalculations.hooks
object is available, effectively providing them access to the actor hooks context.