I am getting a problem in making a countdown timer which will start on clicking on start button and it will stop onClicking on the stop button. I have made that thing on javascript but when I came to reactJs, I am getting unable. I am providing all the codes. And please check what is the problem.
import React, { useState } from "react";
import "./styles.css";
const App = () => {
const [data, setData] = useState(0);
let interval;
return (
<>
<div id="Message"> {data} </div>
<button
onClick={() => {
interval = setInterval(() => {
setData(data + 1);
}, 1000);
}}
>
Start
</button>
<button
onClick={() => {
clearInterval(interval);
}}
>
End
</button>
</>
);
};
export default App;