Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

Cho tôi dự án code React + TailwinCSS cơ bản

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-lite-preview-06-17-thinking’s answer.
  1. User

    Cho tôi dự án code React + TailwinCSS cơ bản

  2. Assistant

    Dưới đây là một dự án React + Tailwind CSS cơ bản, giúp bạn bắt đầu nhanh với giao diện đơn giản hiển thị danh sách việc cần làm (Todo List).


    🎯 Mục tiêu

    • Tạo ứng dụng React sử dụng Vite
    • Cài đặt và cấu hình Tailwind CSS
    • Tạo giao diện đơn giản để thêm và xoá "việc cần làm"

    🛠️ 1. Khởi tạo dự án (Vite + React)

    npm create vite@latest react-tailwind-app --template react
    cd react-tailwind-app
    npm install
    

    🌬️ 2. Cài đặt Tailwind CSS

    Chạy lệnh:

    npm install -D tailwindcss postcss autoprefixer
    npx tailwindcss init -p
    

    Cấu hình tailwind.config.js:

    /** @type {import('tailwindcss').Config} */
    export default {
      content: [
        "./index.html",
        "./src/**/*.{js,ts,jsx,tsx}",
      ],
      theme: {
        extend: {},
      },
      plugins: [],
    }
    

    Thêm Tailwind vào src/index.css:

    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    

    Đảm bảo main.jsx đang import index.css:

    import React from 'react'
    import ReactDOM from 'react-dom/client'
    import App from './App.jsx'
    import './index.css'
    
    ReactDOM.createRoot(document.getElementById('root')).render(
      <React.StrictMode>
        <App />
      </React.StrictMode>,
    )
    

    ✨ 3. Tạo giao diện Todo List

    📁 Cấu trúc thư mục

    src/
    │
    ├── components/
    │   └── TodoItem.jsx
    ├── App.jsx
    └── index.css
    

    🌟 App.jsx

    import { useState } from 'react'
    import TodoItem from './components/TodoItem'
    
    function App() {
      const [todos, setTodos] = useState([])
      const [input, setInput] = useState('')
    
      const addTodo = () => {
        if (input.trim() === '') return
        setTodos([{ id: Date.now(), text: input }, ...todos])
        setInput('')
      }
    
      const deleteTodo = (id) => {
        setTodos(todos.filter(todo => todo.id !== id))
      }
    
      return (
        <div className="min-h-screen bg-gray-100 flex items-center justify-center p-4">
          <div className="bg-white shadow-md rounded p-6 w-full max-w-md">
            <h1 className="text-2xl font-bold mb-4 text-center text-blue-600">Todo List</h1>
            <div className="flex mb-4 gap-2">
              <input
                type="text"
                className="flex-1 px-4 py-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-400"
                placeholder="Việc cần làm..."
                value={input}
                onChange={(e) => setInput(e.target.value)}
              />
              <button
                onClick={addTodo}
                className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
              >
                Thêm
              </button>
            </div>
            <ul>
              {todos.map(todo => (
                <TodoItem
                  key={todo.id}
                  text={todo.text}
                  onDelete={() => deleteTodo(todo.id)}
                />
              ))}
            </ul>
          </div>
        </div>
      )
    }
    
    export default App
    

    💡 components/TodoItem.jsx

    function TodoItem({ text, onDelete }) {
      return (
        <li className="flex justify-between items-center p-2 border-b hover:bg-gray-100 rounded">
          <span>{text}</span>
          <button
            onClick={onDelete}
            className="text-red-500 hover:underline"
          >
            Xoá
          </button>
        </li>
      )
    }
    
    export default TodoItem
    

    ▶️ 4. Chạy thử

    npm run dev
    

    Mở trình duyệt tại địa chỉ http://localhost:5173


    📦 Kết luận

    Bạn vừa hoàn thiện một dự án React đơn giản sử dụng Tailwind CSS với các tính năng:

    • Giao diện đẹp mắt nhờ Tailwind
    • Thêm và xoá todo
    • Cấu trúc gọn gàng, dễ mở rộng

    👉 Gợi ý mở rộng

    • Lưu danh sách việc vào localStorage
    • Thêm chức năng đánh dấu "đã làm"
    • Thêm dark mode ☀️🌙

    Nếu bạn muốn mình tạo riêng repo GitHub hoặc zip source code mẫu, tôi có thể hỗ trợ.

    Bạn muốn thêm tính năng nào không?

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