Skip to content

Instantly share code, notes, and snippets.

@djalmajr
Created April 4, 2024 01:50
Show Gist options
  • Save djalmajr/8a9984d043d7e7bdc9810c4638890062 to your computer and use it in GitHub Desktop.
Save djalmajr/8a9984d043d7e7bdc9810c4638890062 to your computer and use it in GitHub Desktop.
import { html, render } from 'https://cdn.skypack.dev/uhtml@3';
import { effect, signal } from 'https://cdn.skypack.dev/usignal@0.9';
const todos = signal([]);
const add = () => {
const uuid = crypto.randomUUID();
const text = `Item ${uuid.split('-')[1]}`;
todos.value = todos.value.concat({ uuid, text });
};
const remove = (todo) => {
todos.value = todos.value.filter(t => t !== todo);
};
const Todo = (todo) => {
return html`<li @click=${() => remove(todo)}>${todo.text}</li>`;
};
const Todos = () => html`
<div class="app">
<h1>Items (${todos.value.length})</h1>
<button @click=${add}>Add Item</button>
<ul>${todos.value.map(Todo)}</ul>
</div>
`;
const App = () => html`${Todos()}`;
effect(() => render(document.querySelector('#r00t'), App));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment