Skip to content

Commit b12e8d9

Browse files
[lit-html] Expand documentation for TemplateResult and render. (#2849)
1 parent e088732 commit b12e8d9

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

.changeset/eighty-windows-bow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'lit-html': patch
3+
'lit': patch
4+
---
5+
6+
Expand documentation for `render` and `TemplateResult`.

packages/lit-html/src/lit-html.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,17 @@ const ELEMENT_PART = 6;
443443
const COMMENT_PART = 7;
444444

445445
/**
446-
* The return type of the template tag functions.
446+
* The return type of the template tag functions, {@linkcode html} and
447+
* {@linkcode svg}.
448+
*
449+
* A `TemplateResult` object holds all the information about a template
450+
* expression required to render it: the template strings, expression values,
451+
* and type of template (html or svg).
452+
*
453+
* `TemplateResult` objects do not create any DOM on their own. To create or
454+
* update DOM you need to render the `TemplateResult`. See
455+
* [Rendering](https://lit.dev/docs/components/rendering) for more information.
456+
*
447457
*/
448458
export type TemplateResult<T extends ResultType = ResultType> = {
449459
// This property needs to remain unminified.
@@ -609,9 +619,28 @@ export interface RenderOptions {
609619

610620
/**
611621
* Renders a value, usually a lit-html TemplateResult, to the container.
612-
* @param value
613-
* @param container
614-
* @param options
622+
*
623+
* This example renders the text "Hello, Zoe!" inside a paragraph tag, appending
624+
* it to the container `document.body`.
625+
*
626+
* ```js
627+
* import {html, render} from 'lit';
628+
*
629+
* const name = "Zoe";
630+
* render(html`<p>Hello, ${name}!</p>`, document.body);
631+
* ```
632+
*
633+
* @param value Any [renderable
634+
* value](https://lit.dev/docs/templates/expressions/#child-expressions),
635+
* typically a {@linkcode TemplateResult} created by evaluating a template tag
636+
* like {@linkcode html} or {@linkcode svg}.
637+
* @param container A DOM container to render to. The first render will append
638+
* the rendered value to the container, and subsequent renders will
639+
* efficiently update the rendered value if the same result type was
640+
* previously rendered there.
641+
* @param options See {@linkcode RenderOptions} for options documentation.
642+
* @see
643+
* {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates}
615644
*/
616645
export const render = (
617646
value: unknown,

0 commit comments

Comments
 (0)