Core API Overview > @adpt/core > useMethodFrom
useMethodFrom() function
Hook to create an imperative method for a component which forwards calls to another component.
Signature:
export declare function useMethodFrom(provider: Handle | null, methodName: string, defaultVal?: any): void;
Parameters
Parameter | Type | Description |
---|---|---|
provider | Handle | null | a Handle an Element that has method methodName . In the case that provider is null , then defaultVal will be returned. |
methodName | string | The name that will be used for both the imperative method created on the invoking component and that will be invoked on the provider component. |
defaultVal | any | The value that will be returned if provider is null or if provider does not reference an Element in the DOM at the time of invocation. |
Returns:
void
Remarks
Creates an imperative method named methodName
on the component from which this hook is invoked, which calls the imperative method of the same name on the component instance referenced by provider
.
When this component's method methodName
is called by another component, typically via useMethod
, if provider
does not reference a valid Element, defaultVal
will be returned. If methodName
does not exist on provider
or is not a function, an error will be thrown. Otherwise, the provider Element's methodName
method will be invoked and its return value returned to the caller.