Hi,
Good day Everyone. So I’m on this project in Front-End Development the 25+5 Clock and I am using ReactJS, the problem is whenever I click the “Run Test” I’ve noticed that all button which has onClick was clicked and it changed the default value of the session and break length since it was clicked upon clicking the “Run Test”
The function “onIncrement” and “onDecrement” is the function for onClick event.
Here’s my code:
const App = () => {
const [breaklength, setBreakLength] = useState(5);
const [sessionlength, setSessionLength] = useState(25);
const [play, setPlay] = useState(false);
let currentBreakLength = breaklength;
let currentSessionLength = sessionlength;
const onIncrement = (e) => {
let id = e.target.id;
if (id === 'break-increment') setBreakLength((currentBreakLength += 1));
else if (id === 'session-increment')
setSessionLength((currentSessionLength += 1));
};
const onDecrement = (e) => {
let id = e.target.id;
if (id === 'break-decrement') {
if (currentBreakLength > 1) setBreakLength((currentBreakLength -= 1));
} else if (id === 'session-decrement') {
if (currentSessionLength > 1)
setSessionLength((currentSessionLength -= 1));
}
};
const onReset = () => {
setSessionLength(25);
};
return (
<div className='App'>
<div className='wrapper'>
<TimerControl
onIncrement={onIncrement}
onDecrement={onDecrement}
sessionlength={sessionlength}
breaklength={breaklength}
/>
<TimerDisplay
onReset={onReset}
sessionlength={sessionlength}
breaklength={breaklength}
/>
</div>
</div>
);
};
I hope someone can help me.