Programming Exercises

Build a counter component that increases the count by 1 every time a button is clicked.

Easy

Problem Statement

Build a counter component that increases the count by 1 every time a button is clicked.

Sample Output

Initially: Count: 0
 After clicking the button: Count: 1, Count: 2, etc.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const Counter = () => { const [count, setCount] = useState(0); const handleIncrement = () => { // Increment the count state }; return ( <div> <p>Count: {count}</p> <button onClick={handleIncrement}>Increment</button> </div> ); }; export default Counter;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
Initially: Count: 0
 After clicking the button: Count: 1, Count: 2, etc.