Files
owl/src/refs.ts
T

19 lines
557 B
TypeScript
Raw Normal View History

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.
*/
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
2020-11-26 16:45:25 +01:00
const node = getCurrent()!;
return {
get el(): T | null {
return node.refs[name] || null;
2020-11-26 16:45:25 +01:00
},
};
}