Skip to main content
React Interview Questions Concept Queue P0 Medium

The wrong room keeps receiving updates

A ChatRoom subscribes to a room in an effect. After switching from room A to B, the UI still receives messages for A. Walk through the expected subscription lifecycle and explain how you would check that the fix works in development.

Official Reference

Model Answer & Explanation

Make the effect depend on the room ID and any other reactive subscription inputs. Return cleanup that unsubscribes the exact subscription created for that run. On a room change React cleans up the previous setup before running the new one, and cleans up on unmount. At the root, development Strict Mode can run an extra setup/cleanup cycle, so verify there is exactly one active subscription after mounting and switching.

What a Strong Answer Covers

  • Use current dependencies and clean up the subscription that was actually created.
  • Test lifecycle behavior after setup, room changes and unmount.
Follow-up Interview Question · How would you guard against an already-queued message from the room that was just closed?

Module Context & References

React · Applied concepts Explain the state, identity and effect bugs behind real UI behavior.
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.