Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

How to create next js todo application

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    How to create next js todo application

  2. Claude Assistant

    Creating a Next.js Todo Application

    Here's how to build a simple todo app with Next.js:

    1. First, create a new Next.js project:
    npx create-next-app@latest todo-app
    cd todo-app
    
    1. Create the main todo component in app/page.js:
    "use client";
    import { useState } from 'react';
    
    export default function TodoApp() {
      const [todos, setTodos] = useState([]);
      const [input, setInput] = useState('');
    
      const addTodo = () => {
        if (input.trim()) {
          setTodos([...todos, { id: Date.now(), text: input, completed: false }]);
          setInput('');
        }
      };
    
      const toggleTodo = (id) => {
        setTodos(todos.map(todo => 
          todo.id === id ? { ...todo, completed: !todo.completed } : todo
        ));
      };
    
      const deleteTodo = (id) => {
        setTodos(todos.filter(todo => todo.id !== id));
      };
    
      return (
        <div className="max-w-md mx-auto mt-10 p-6 bg-white rounded-lg shadow-md">
          <h1 className="text-2xl font-bold mb-4">Todo App</h1>
          
          <div className="flex mb-4">
            <input
              type="text"
              value={input}
              onChange={(e) => setInput(e.target.value)}
              onKeyPress={(e) => e.key === 'Enter' && addTodo()}
              className="flex-grow p-2 border border-gray-300 rounded-l"
              placeholder="Add a task..."
            />
            <button 
              onClick={addTodo}
              className="bg-blue-500 text-white px-4 py-2 rounded-r"
            >
              Add
            </button>
          </div>
          
          <ul>
            {todos.map(todo => (
              <li key={todo.id} className="flex items-center p-2 border-b">
                <input
                  type="checkbox"
                  checked={todo.completed}
                  onChange={() => toggleTodo(todo.id)}
                  className="mr-2"
                />
                <span className={todo.completed ? 'line-through flex-grow' : 'flex-grow'}>
                  {todo.text}
                </span>
                <button 
                  onClick={() => deleteTodo(todo.id)}
                  className="text-red-500"
                >
                  Delete
                </button>
              </li>
            ))}
          </ul>
        </div>
      );
    }
    
    1. Start your development server:
    npm run dev
    

    Would you like me to explain or break down the code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.