2020-11-26 16:45:25 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// useRef
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import { getCurrent } from "./component/component_node";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The purpose of this hook is to allow components to get a reference to a sub
|
|
|
|
|
* html node or component.
|
|
|
|
|
*/
|
2021-11-10 08:18:25 +01:00
|
|
|
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
|
2020-11-26 16:45:25 +01:00
|
|
|
const node = getCurrent()!;
|
|
|
|
|
return {
|
2021-11-10 08:18:25 +01:00
|
|
|
get el(): T | null {
|
|
|
|
|
return node.refs[name] || null;
|
2020-11-26 16:45:25 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|