Sometimes you need to render HTML elements on a web page. And like Goldilocks' search for "just right", you have to try a few techniques before you...
For further actions, you may consider blocking this person and/or reporting abuse
Nice article!
typescript-lit-html-plugin is great, but I would recommend the ts-lit-plugin for tsc and lit-plugin for VS Code - they have a lot more features around type checking templates, and bindings to attributes and properties, including for custom elements. See github.com/runem/lit-analyzer/tree... and marketplace.visualstudio.com/items...
I’ll check those out. Thanks for sharing.
thanks for the article, discovered about lit-html now!
curious to know why markup is created in
JavaScript
instead ofHTML
.then call this in
JavaScript
(with data) for dynamic rendering. given that there may be several dynamic components in a page that could help in code readability.One reason is that those
${...}
expressions are part of JavaScript, you can't just put that in HTML and have them do anything.Another is that we don't have a great way of co-locating HTML and JavaScript right now. You could put HTML templates in the main document and your component in JS, but that's a pretty bad developer experience, and it would be tough-to-impossible to scale to 3rd party components.
And most importantly is that lit-html doesn't have any of its own control-flow constructs. It has no if-statements or loops - that's all left up to JavaScript. We'd have to re-implement these for HTML.
Hopefully soon we'll have HTML modules in the browser and then we can do something like this.
Thanks for contributing to the conversation!
thanks for the reply, Justin!
Well done! Justin has done a remarkable job keeping lit-html lean and mean. lit-html and it's equally lean base class lit-element really changed the way I think about creating applications. This article is a nice demonstration and introduction. It would be a great addition to the curated Awesome lit-html repo. github.com/web-padawan/awesome-lit...
Thanks! Looks like it was added.
Lit-html works great with a state management library like redux. I manage to create a TodoMVC app binding lit-html with a homemade redux using directives.
That's cool, thanks for sharing
Theres also haunted which adds react-like hooks to lit-html!
neat!
Cool post!
VS Code and Type Script
Here
Type Script
reminds me of old days people writingShare Point
Using lit-HTML's declarative syntax, it is easy to build lightweight Web Components as well as use other existing Web Components in our applications. That really works for me.