mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
c03042b44d
Refs to component expose a lot of implementation details that should be private to parents. Parent to child communication should go through props.
19 lines
557 B
TypeScript
19 lines
557 B
TypeScript
// -----------------------------------------------------------------------------
|
|
// 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 } {
|
|
const node = getCurrent()!;
|
|
return {
|
|
get el(): T | null {
|
|
return node.refs[name] || null;
|
|
},
|
|
};
|
|
}
|