Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

Hi

  1. User

    Hi

  2. Assistant

    Hello! How can I assist you today?

  3. User

    Hwi

  4. Assistant

    Hi there! How can I help you today?

  5. User

    generate code for todoapp

  6. Assistant

    Sure! Here's a simple Todo List App using React. This example includes adding, toggling (complete/incomplete), and deleting todo items.

    import React, { useState } from 'react';
    
    function TodoApp() {
      const [todos, setTodos] = useState([]);
      const [input, setInput] = useState('');
    
      const addTodo = () => {
        if (input.trim() === '') return;
        setTodos([...todos, { id: Date.now(), text: input.trim(), 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 style={{ maxWidth: 400, margin: '2rem auto', fontFamily: 'Arial, sans-serif' }}>
          <h2>Todo List</h2>
          <input
            type="text"
            placeholder="Add a todo"
            value={input}
            onChange={(e) => setInput(e.target.value)}
            onKeyDown={(e) => e.key === 'Enter' && addTodo()}
            style={{ padding: '0.5rem', width: '70%' }}
          />
          <button onClick={addTodo} style={{ padding: '0.5rem', marginLeft: '0.5rem' }}>Add</button>
          <ul style={{ listStyle: 'none', padding: 0 }}>
            {todos.map(todo => (
              <li key={todo.id} style={{ margin: '1rem 0', display: 'flex', alignItems: 'center' }}>
                <input
                  type="checkbox"
                  checked={todo.completed}
                  onChange={() => toggleTodo(todo.id)}
                  style={{ marginRight: '0.5rem' }}
                />
                <span style={{ flexGrow: 1, textDecoration: todo.completed ? 'line-through' : 'none' }}>
                  {todo.text}
                </span>
                <button onClick={() => deleteTodo(todo.id)} style={{ marginLeft: '0.5rem' }}>
                  Delete
                </button>
              </li>
            ))}
          </ul>
        </div>
      );
    }
    
    export default TodoApp;
    

    How to use:

    1. Create a React project (using Create React App or another setup).
    2. Save this code as TodoApp.jsx.
    3. Import and use <TodoApp /> in your main component.

    If you want code in a different language/framework or with more features, just let me know!

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