You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lit-html templates are plain JavaScript and combine the familiarity of writing HTML with the power of JavaScript. lit-html takes care of efficiently rendering templates to DOM, including efficiently updating the DOM with new values.
import{html,render}from'lit-html';// This is a lit-html template function. It returns a lit-html template.consthelloTemplate=(name)=>html`<div>Hello ${name}!</div>`;// This renders <div>Hello Steve!</div> to the document bodyrender(helloTemplate('Steve'),document.body);// This updates to <div>Hello Kevin!</div>, but only updates the ${name} partrender(helloTemplate('Kevin'),document.body);
lit-html provides two main exports:
html: A JavaScript template tag used to produce a TemplateResult, which is a container for a template, and the values that should populate the template.
render(): A function that renders a TemplateResult to a DOM container, such as an element or shadow root.
Installation
$ npm install lit-html
Forward compatibility with lit-html 2.0
lit-html 2.0 has a new directive authoring API that has been back-ported to lit-html 1.4 in order to ease upgrading.
The lit-html 2.0 directive API is available in new modules whose paths are the same in lit-html 1.4 and 2.0, allowing code to import and use the APIs against either version.