react create a page with a button that increments a number, which is shown as a text
- User
react create a page with a button that increments a number, which is shown as a text
Assistant
Sure, here's an example of how you can create a page with a button that increments a number and displays it as text using React:
import React, { useState } from 'react'; function Counter() { const [count, setCount] = useState(0); const handleClick = () => { setCount(count + 1); }; return ( <div> <button onClick={handleClick}>Increment</button> <p>Count: {count}</p> </div> ); } export default Counter;This component uses the
useStatehook to create a state variablecountand initialize it to 0. ThehandleClickfunction is called when the button is clicked, and it updates the state by calling the function and passing the new value ().
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.