html`` DocumentFragmentNote that Thunderous does not sanitize the input of the(invalid icon)
html`` html``
import { customElement, html } from 'thunderous';
const MyElement = customElement(() => {
const cond = true;
return html`
<p>
${cond ? html`<span>True</span>` : html`<span>False</span>`}
</p>
`;
});
Short-circuit evaluation is not recommended because(invalid icon)
false null undefined DocumentFragment key
import { customElement, html } from 'thunderous';
const MyElement = customElement(() => {
const list = [{ id: 1, text: 'Item 1' }, { id: 2, text: 'Item 2' }];
return html`
<ul>
${list.map((item) => html`<li key="${item.id}">${item.text}</li>`)}
</ul>
`;
});
derived() html``For more information on signals, see the(invalid icon)
import { customElement, html, derived, createSignal } from 'thunderous';
const MyElement = customElement(() => {
const [cond, setCond] = createSignal(true);
const [list, setList] = createSignal([{ id: 1, text: 'Item 1' }, { id: 2, text: 'Item 2' }]);
return html`
<p>
${derived(() => cond() ? html`<span>True</span>` : html`<span>False</span>`)}
</p>
<ul>
${derived(() => list().map((item) => html`<li key="${item.id}">${item.text}</li>`))}
</ul>
`;
});
derived()
import { customElement, html, derived, createSignal } from 'thunderous';
const MyElement = customElement(() => {
const [cond, setCond] = createSignal(true);
return html`
<button class="primary ${derived(() => cond() ? 'primary--active' : '')}">
Click me
</button>
`;
});
// alternatively, for a cleaner template...
const MyElement2 = customElement(() => {
const [cond, setCond] = createSignal(true);
const activeClass = derived(() => cond() ? 'primary--active' : '');
return html`
<button class="primary ${activeClass}">
Click me
</button>
`;
});