State for counters

Report a typo

You can use state in React to store specific data related to a component, like a counter value. Here's how to write a functional React component called Counter which displays a count value. It will also provide buttons to increase or decrease the count using state. Just fill in the blanks to finish the program.

Fill in the gaps with the relevant elements
import React, { useState } from 'react';

const Counter = () => {
  const [, setCount] = (0);

  const increment = () => {
    setCount(count  1);
  };

  const decrement = () => {
    setCount(count  1);
  };

  return (
    <div>
      <button onClick={}>Increment(+)</button>
      <button onClick={}>Decrement(-)</button>
      <p>Count: {count}</p>
    </div>
  );
};
useState+countuseEffectincrement-decrement

Create a free account to access the full topic