joe, Yesterday, we looked at how to define our own web components and how to use web components that were defined using Shoelace. Today, I figured that we should take a quick look at Lit. Lit is a simple library for building fast, lightweight web components.
Let’s see what yesterday’s “hello world” demo would look like with Lit.
See the Pen by Joe Steinbring (@steinbring)
on CodePen.The syntax is a lot more pleasing in my humble opinion. Let’s see how to do something a little more complex, though.
See the Pen by Joe Steinbring (@steinbring)
on CodePen.This example defines
<blog-feed></blog-feed>
with ajson
parameter. Lit has a<a href="https://lit.dev/docs/components/lifecycle/#connectedcallback">connectedCallback()</a>
lifecycle hook that is invoked when a component is added to the document’s DOM. Using that, we are runningthis.fetchBlogFeed()
which in turn runningawait fetch()
. It is then using https://lit.dev/docs/components/rendering/ to render the list items.I am kind of digging Lit.
Add comment