give me cde for a smple react app
- User
give me cde for a smple react app
Assistant
Here's a simple React app that displays a counter with increment/decrement buttons. This example includes everything you need to get started:
1. Set Up the Project
First, create a new React app using Create React App (or your preferred method):
npx create-react-app simple-counter-app cd simple-counter-app2. Replace
src/App.jswith this code:import React, { useState } from 'react'; import './App.css'; function App() { const [count, setCount] = useState(0); const increment = () => setCount(count + 1); const decrement = () => setCount(count - 1); const reset = () => setCount(0); return ( <div className="App"> <header className="App-header"> <h1>Simple Counter App</h1> <div className="counter-display"> <h2>{count}</h2> </div> <div className="button-group"> <button onClick={decrement} className="counter-button">-</button> <button onClick={reset} className="counter-button reset">Reset</button> <button onClick={increment} className="counter-button">+</button> </div> </header> </div> ); } export default App;3. Replace
src/App.csswith this styling:.App { text-align: center; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: calc(10px + 2vmin); color: white; background-color: #282c34; } .App-header { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2rem; } .counter-display { padding: 2rem; background-color: #61dafb; border-radius: 10px; width: 200px; color: #282c34; font-size: 3rem; } .button-group { display: flex; gap: 1rem; } .counter-button { padding: 1rem 2rem; font-size: 1.5rem; background-color: #61dafb; color: #282c34; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } .counter-button:hover { background-color: #21a1c4; } .counter-button.reset { background-color: #ff6b6b; } .counter-button.reset:hover { background-color: #e05656; }4. Run the App
Start the development server:
npm startThis will open your app in the browser at
http://localhost:3000. You should see:- A title "Simple Counter App"
- A counter display showing the current count
- Three buttons: "-" to decrement, "Reset" to set to 0, and "+" to increment
Key Concepts Demonstrated:
- React Hooks: Using
useStateto manage component state - Event Handling: Button click handlers
- Component Structure: Basic React component structure
- Styling: CSS for a clean, responsive layout
- JSX Syntax: Combining HTML-like syntax with JavaScript
You can expand this by adding features like:
- Local storage to persist the count
- Animation effects
- More complex state management
- Additional styling or themes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.