Overview
React Hooks: useEffect - 1
GreatFrontEnd has better questions!
We don't create questions because GreatFrontEnd already has the best possible library of questions and we recommend the same to our community.
Questions are deprecated!
These are the interview practice questions from the legacy versions of Frontend Hire. Only the ones with a video solution are available. Moving forward, we won't be releasing more questions as this is not our strongest content.
Fork on Stackblitz
Click on the "Fork" button on the bottom-left corner of the editor to fork the code on Stackblitz and to solve this question in a separate browser tab.
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
seconds
state is being used in theuseEffect
dependency 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
useEffect
dependencies.
Bonus
- Abstract out the timer logic into a custom hook. An empty file
useTimer.js
has already been created for you!
Resources to Refer
Promote your product or service here
Get in front of thousands of frontend developers and tech enthusiasts with our advertising slots.
GreatFrontEnd has better questions!
We don't create questions because GreatFrontEnd already has the best possible library of questions and we recommend the same to our community.
Last updated on