Write simple react component with button and incremental state. If the count reach 10…
- User
Write simple react component with button and incremental state. If the count reach 10 clicks, show alert
Assistant
Here's a simple React component that includes:
- A button
- A count state that increments when the button is clicked
- An alert shown when the count reaches 10
✅ Example:
Counter.jsimport React, { useState } from 'react'; const Counter = () => { const [count, setCount] = useState(0); const handleClick = () => { const newCount = count + 1; setCount(newCount); if (newCount === 10) { alert('You reached 10 clicks!'); } }; return ( <div> <h1>Count: {count}</h1> <button onClick={handleClick}>Click Me</button> </div> ); }; export default Counter;
💡 How to Use
- Make sure you have a React environment set up (e.g., via ).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.