Junior — Senior
Detect and fix bugs in a React component
livecode
Task condition
In this task, you need to find and fix errors in a small React component implemented using hooks useState and useEffect. Attach the corrected version of the code, ensuring the counter works correctly and there are no syntax errors.
import React, { useState, useEffect } from 'react';
const Counter = () => {
const [count, setCount] = useState(0);
useEffect(() => {
console.log(`Count updated: ${count}`);
if (count === 5) {
setCount(0);
}
}, [count]);
const increment = () => {
setCount(count + 1);
};
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
};