Question
90% of the bugs in React applications are caused due to useEffect.
Why did the React component feel lost? Because it was missing its useEffect dependencies!
Objective
Identify and fix the bugs related to resetting the timer.
Requirements
- Identify the Bug: The provided App component has a timer that can be reset. However, there's a bug in the useEffect implementation.
- Understand the Dependency Array: Analyze how the
secondsstate is being used in theuseEffectdependency array. - Fix the Bug: Modify the code to correctly reset the timer without causing unnecessary re-renders or other side effects.
- Understand why your solution works and how it addresses the issue with the
useEffectdependencies.
Bonus
- Abstract out the timer logic into a custom hook. An empty file
useTimer.jshas already been created for you!