UNPKG

react-aptor

Version:
20 lines (19 loc) 1.17 kB
import type { DependencyList, Ref, RefObject } from 'react'; export type APIGenerator = () => unknown; export type GetAPI<TInstance, TParams> = (instance: TInstance | null, prams?: TParams) => APIGenerator; export type Instantiate<TInstance, TElement, TParams> = (node: TElement | null, params?: TParams) => TInstance; export type Destroy<TInstance, TParams> = (instance: TInstance, params?: TParams) => void; export interface AptorConfiguration<TInstance, TElement, TParams> { getAPI: GetAPI<TInstance, TParams>; instantiate: Instantiate<TInstance, TElement, TParams>; destroy?: Destroy<TInstance, TParams>; params?: TParams; } /** * react aptor(api-connector) a hook which connect api to react itself * @param ref - react forwarded ref * @param {Object} configuration - configuration object for setup * @param {Array} [deps=[]] - react dependencies array * @return domRef - can be bound to dom element */ export declare function useAptor<TInstance, TElement extends HTMLElement = HTMLElement, TParams = unknown>(ref: Ref<unknown>, configuration: AptorConfiguration<TInstance, TElement, TParams>, deps?: DependencyList): RefObject<TElement>;