Promises
Promise as a value of an expression is not supported. However, the library supports promises by the html.resolve
method.
html.resolve(promise: Promise, placeholder: Function, delay = 200): Function
arguments:
promise
- promise, which should resolve/reject update functionplaceholder
- update function for render content until promise is resolved or rejecteddelay
- delay in milliseconds, after which placeholder is rendered
returns:
update function compatible with content expression
const promise = asyncApi().then(...);
html`
<div>
${html.resolve(
promise
.then((value) => html`<div>${value}</div>`)
.catch(() => html`<div>Error!</div>`),
html`Loading...`,
)}
</div>
`
Click and play with web component example connected to external API:
Last updated
Was this helpful?