Difficulty: 5/10resource management, memory leaks, event subscriptions1saves applications from unwanted behaviours like memory leaks2To avoid race conditions in async requests.3To manage subscriptions in your applicationScenario Questions0-2 years experience1You added a window resize listener inside a useEffect. What steps do you take to make sure it doesn't keep firing after the component unmounts?2If you set a setInterval inside an effect but forget to return a cleanup function, what symptom might you notice when navigating away from the page?2-5 years experience1Our component opens a WebSocket connection in useEffect and started receiving duplicate messages after users navigate between routes. How would you debug and fix the issue?Follow-up QuestionsHow would you verify that your cleanup logic actually runs in a test?What problems arise if the cleanup closes over stale state or props?When an effect runs frequently due to changing dependencies, how do you balance cleanup cost versus correctness?Suggest Improvement