give me cde for a smple react app
- User
give me cde for a smple react app
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
give me cde for a smple react app
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a simple React app that creates a basic todo list with add/delete functionality:
// App.jsx
import React, { useState } from 'react';
import './App.css';
function App() {
const [todos, setTodos] = useState([]);
const [input, setInput] = useState('');
const addTodo = () => {
if (input.trim()) {
setTodos([...todos, { id: Date.now(), text: input }]);
setInput('');
}
};
const deleteTodo = (id) => {
setTodos(todos.filter(todo => todo.id !== id));
};
return (
<div className="app">
<h1>Todo List</h1>
<div className="add-todo">
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Add a task..."
onKeyPress={(e) => e.key === 'Enter' && addTodo()}
/>
<button onClick={addTodo}>Add</button>
</div>
<ul className="todo-list">
{todos.map(todo => (
<li key={todo.id}>
{todo.text}
<button onClick={() => deleteTodo(todo.id)}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default App;
/* App.css */
.app {
max-width: 600px;
margin: 20px auto;
padding: 20px;
font-family: Arial, sans-serif;
}
.add-todo {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
input {
flex: 1;
padding: 8px;
font-size: 16px;
}
button {
padding: 8px 16px;
background: #0066ff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0052cc;
}
.todo-list {
list-style: none;
padding: 0;
}
li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
margin: 5px 0;
background: #f5f5f5;
border-radius: 4px;
}
To use this:
npx create-react-app my-todo-app
cd my-todo-app
Replace the contents of src/App.jsx and src/App.css with the code above
Start the development server:
npm start
Features:
Want to add more features like editing, completion status, or persistence? Let me know!