Renders a htm tagged template asyncly into a string
npm install async-htm-to-stringRenders a htm tagged template asyncly into a string.






``bash`
npm install async-htm-to-string
`javascript
const { html, renderToString } = require('async-htm-to-string');
const customTag = ({ prefix }, children) => html
;
const dynamicContent = 'bar';
// Will equal "foo-bar"
const result = await renderToString(html<${customTag} prefix="foo">${dynamicContent}${customTag}>);
`$3
The library has full support for async values:
* Async Components: Components can be
async functions
* Async Children: Children can be Promises or arrays of Promises
* Deeply Nested: Resolved values are recursively processed
* Concurrency: Uses buffered-async-iterable to process async arrays concurrently while maintaining order`javascript
const AsyncComponent = async ({ id }) => {
const data = await fetchData(id);
return html;
};// will be awaited and rendered
const result = await renderToString(html
);
`API
$3
Is
h() bound to htm (htm.bind(h)). Used with template literals, like:`javascript
const renderableElement = html;
`$3
If you need to provide pre-escaped raw HTML content, then you can use
rawHtml as either a template literal or by calling it with the`javascript
const renderableElement = rawHtml;
``javascript
const renderableElement = rawHtml('&');
`You can also use the result of any of those
rawHtml inside html, like:`javascript
const renderableElement = html&};
`$3
The inner method that's
htm is bound to.$3
Takes the output from
html and returns an async iterator that yields the strings as they are rendered$3
Same as
render(), but asyncly returns a single string with the fully rendered result, rather than an async iterator.Helpers
$3
Asyncly loops over an iterable (like eg. an async iterable) and concatenates together the result into a single string that it resolves to. The brains behind
renderToString()`.