The library's reminder letters: a tag function gets the string pieces and the values apart, from a template that really runs. The base of safe sql`` and…
Why it matters
Tagged templates are the engine behind styled-components, gql, and safe html/sql tags. Because a tag sees dynamic values apart from static text, it can escape or parse only the parts that need it.
The key idea
A tag is just a function; the template is cut into static pieces and values
Try it in this playground
Write a template with four values Use the insert buttons. Watch strings stay one longer than values.
Start or end the template with a value An empty piece at an end shows as a thin numbered mark on the board.
Try three different tags The same template, a different function, a different result. The pieces stay the same.
Escape a comment with the tag aman Insert ${komentar} and pick aman: the HTML tags in its value become text.