Public
Back
Version 16
8/23/2024
import { init, tx, id } from 'npm:@instantdb/core'
// ID for app: wonderful-wombat
const APP_ID = '97f33fe4-2c61-434f-8dea-fa5c940f2d6f'
const db = init({ appId: APP_ID })
db.subscribeQuery({ todos }, (resp) => {
if (resp.error) {
renderError(resp.error.message); // Pro-tip: Check you have the right appId!
return;
}
if (resp.data) {
render(resp.data);
}
});
// Write Data
// ---------
function addTodo(text: string) {
db.transact(
tx.todos[id()].update({
text,
done: false,
createdAt: Date.now(),
})
);
}
function deleteTodoItem(tod) {
db.transact(tx.todos[todo.id].delete());
}
function toggleDone(todo) {
Updated: August 23, 2024