useHost
Hook that creates a reference that curren is the instance of the webcomponent.

Syntax

1
const refHost = useHost();
Copied!
Returns the instance of the webcomponent in reference format, this reference allows to extend behaviors when creating customHooks.

Example

1
import { useHost, useEffect } from "atomico";
2
3
function useListener(type: string, callback: (ev: Event) => void) {
4
const ref = useHost();
5
useEffect(() => {
6
const { current } = ref;
7
current.addEventListener(type, callback);
8
return () => current.removeEventListener(type, callback);
9
}, []);
10
}
Copied!
From the example we can highlight that useListener is a customHook that allows listening to an event from the webcomponent without the need to link said event to the VirtualDOM.
Last modified 3mo ago
Copy link
Edit on GitHub