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.
State vs Props
State for counters
Report a typo
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>
);
};Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.