2 ms·
I used this technique in a project I'm working on extensively. This works great for server-side rendered projects, because you can just combine the HTML inside
by peebeebee 3y ago
I used this technique in a project I'm working on extensively.
This works great for server-side rendered projects, because you can just combine the HTML inside and the custom-tag in a partial, and re-use this partial like a default component.
A nice advantage is also that it will auto-execute code when you include components in the DOM through the connectedCallback() function. No need to do manual stuff, or wait for onDOMContentLoaded.
BUT when you go more advanced, like intra-component communication, or nested component structures, it starts to become a bit troublesome.
Or you'll dream of some reactive templating or other advanced features, and you'll check out what LIT-components are doing...
I feel that in most simple cases doing vanilla enhancements on some .js-something classes are is even easier that using this technique. No need for a custom-element. Just go back to the jQuery days. :)