Tuesday, May 13, 2025

BIS601 - FSD - React Application to Increment and Decrement a counter using Functional Components

 React application using functional components:

import React, { useState } from 'react';


function App() {

  const [count, setCount] = useState(0);


  const handleIncrement = () => setCount(count + 1);

  const handleDecrement = () => setCount(count - 1);


  return (

    <div style={{ textAlign: 'center', marginTop: '2rem' }}>

      <h1>Functional Counter</h1>

      <h2>{count}</h2>

      <button onClick={handleIncrement}>Count Up</button>

      <button onClick={handleDecrement} style={{ marginLeft: '1rem' }}>

        Count Down

      </button>

    </div>

  );

}


export default App;


No comments:

Post a Comment