Programming Exercises

Build a React component that increments or decrements a number using '+' and '-' buttons.

Easy

Problem Statement

Build a React component that increments or decrements a number using '+' and '-' buttons.

Sample Output

Initially: Value: 0
 Clicking '+' increments and '-' decrements the value.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const IncrementDecrement = () => { const [value, setValue] = useState(0); return ( <div> <p>Value: {value}</p> <button onClick={() => { // Increment the value }}>+</button> <button onClick={() => { // Decrement the value }}>-</button> </div> ); }; export default IncrementDecrement;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
Initially: Value: 0
 Clicking '+' increments and '-' decrements the value.