Learn Lit fast. This is a quick overview of how to use Lit core features compressed into one minute. Remember to pause the video if you need time to understand something!
This lesson uses Lit v2.
To learn more about Lit and the rest of the features we haven't covered, visit the official website.
Rodrigo Pombo: [0:00] To create a component with Lit, you need to extend the LitElement class. Then, add the render() method and use that tag template literal to return html. You also need to use the customElement decorator, so you can use the element name from anywhere in your app.
[0:16] If you want to pass data to a custom element, use a class field with the property decorator, then you can render it inside the template literal.
[0:24] Templates can also include event listeners with this syntax. You can define internal state with the state decorator. Every time you change its state, Lit will re-render the component.
[0:37] You can dispatch CustomEvent to send data to the parent. CustomEvents can be handled in the same way as DOM events. If you want to repeat something based on a list, you map the array and nest the list of tag template literals.
[0:53] There is also a static styles property that only affect the elements within the component.