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
Copy file name to clipboardExpand all lines: packages/lit-dev-content/site/docs/templates/directives.md
+93
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,15 @@ Lit includes a number of built-in directives to help with a variety of rendering
127
127
<tr>
128
128
<td>
129
129
130
+
[`keyed`](#keyed)
131
+
132
+
</td>
133
+
<td>Associates a renderable value with a unique key, forcing the DOM to re-render if the key changes.</td>
134
+
</tr>
135
+
136
+
<tr>
137
+
<td>
138
+
130
139
[`guard`](#guard)
131
140
132
141
</td>
@@ -1015,6 +1024,90 @@ The `cache` directive caches the generated DOM for a given expression and input
1015
1024
1016
1025
Explore `cache` more in the [playground](/playground/#sample=examples/directive-cache).
1017
1026
1027
+
1028
+
### keyed
1029
+
1030
+
Associates a renderable value with a unique key. When the key changes, the previous DOM is removed and disposed before rendering the next value, even if the value—such as a template—is the same.
`keyed` is useful when you're rendering stateful elements and you need to ensure that all state of the element is cleared when some critical data changes. It essentially opts-out of Lit's default DOM reuse strategy.
1067
+
1068
+
`keyed` is also useful in some animation scenarios if you need to force a new element for "enter" or "exit" animations.
0 commit comments