Build a Todo App
Learn the basics by building a todo application
In this guide, you'll build a simple todo app that demonstrates core platform features.
What You'll Build
A todo app with:
- Create, read, update, and delete todos
- Real-time sync across devices
- User authentication
Prerequisites
Make sure you have Node.js 18+ installed before starting.
Step 1: Project Setup
1
Create a new projectnpx create-demo-app todo-app
cd todo-app2
Install dependenciesnpm install3
Start the dev servernpm run devStep 2: Create the Todo List
import { db } from '@demo/database';
import { useState, useEffect } from 'react';
function TodoList() {
const [todos, setTodos] = useState([]);
useEffect(() => {
// Subscribe to todos
return db.collection('todos').subscribe(setTodos);
}, []);
const addTodo = async (text) => {
await db.collection('todos').create({
text,
completed: false,
createdAt: new Date()
});
};
return (
<div>
{todos.map(todo => (
<TodoItem key={todo.id} todo={todo} />
))}
</div>
);
}
Step 3: Add Toggle and Delete
const toggleTodo = async (id, completed) => {
await db.collection('todos').update(id, { completed: !completed });
};
const deleteTodo = async (id) => {
await db.collection('todos').delete(id);
};
