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 with a button that increments a counter and shows an alert when it reaches 10:
import React, { useState, useEffect } from 'react'; const ClickCounter = () => { const [count, setCount] = useState(0); useEffect(() => { if (count === 10) { alert('You reached 10 clicks!'); } }, [count]); const handleClick = () => { setCount(count + 1); }; return ( <div> <h2>Click Counter</h2> <p>Current count: {count}</p> <button onClick={handleClick}> Click me! </button> </div> ); }; export default ClickCounter;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.