I'm building a counter with a start/stop button using React. I keep getting an object error on codepen in my functional component. I've narrowed it down to the setInterval line (line 32 in codepen) within useEffect, but I can't figure out what's wrong with it.
Codepen: https://codepen.io/sirstevekim/pen/zYROyxj
const App = () => {
const [time, setTime] = React.useState(0);
const [isRunning, setIsRunning] = React.useState(false);
const counter = () => setTime(time + 1);
React.useEffect(() => {
const interval = null;
if (isRunning === false) {
interval = setInterval(counter, 1000);
} else {
clearInterval(interval);
}
return () => {clearInterval(interval)};
}, [isRunning]);
const handleStartStop = () => {
setIsRunning(!isRunning);
}
const handleReset = () => {
setIsRunning(false);
setTime(0);
}
return (
<div className="app">
<Timer time={time} />
<ControlButtons
handleStartStop={handleStartStop}
handleReset={handleReset}
/>
</div>
);
}