onMount hook of toDOM

I want to access the element rendered by “toDOM”, is there any hook can do that?

No, but you can just create actual DOM elements in toDOM and return those.

You mean I can write like this?

toDOM() {
  const someElement = document.createElement('div');
  someElement.textContent = 'hello world';

  return someElement;

If I can do like this, how can I express the 0 of ['div', 0] ??

Use the {dom, contentDOM} return format.

1 Like

But if I want to make the content I input automatically become div’s content ( Just like 0 means ), what should I put into contentDOM ?

The parent of where your 0 was (which may be the same element as dom).

1 Like

Thanks a lot !!

Hey, I got another question :joy: When I need bind an event listener to that element, how can I safely remove it to avoid memory leaks ?

It hasn’t been necessary to remove event listeners to prevent memory leaks for about 10 years (unless you are somehow holding on to a reference to the DOM element the listener is registered on).

1 Like