Question presented to candidate: "An effect connects to a chat room and shows a notification using the current theme. Changing the theme should not reconnect. How do you express that?"
What a strong answer should cover:
- The problem: some values an effect uses are not values it should react to. The dependency array has only one setting for both.
useEffectEventsplits them: code inside an Effect Event always sees the latest props and state, but the event itself is not a dependency.- So the effect re-runs only for genuinely reactive values, while still reading current ones.
- The alternatives it replaces: lying to the lint rule (stale closure), or a ref updated every render (verbose, easy to misuse).
- Constraints: only call an Effect Event from inside an effect in the same component — never pass it to another component or call it during render.
- It is stable on React 19.2.8, exported from
react(notexperimental_useEffectEvent). - The distinction to state: props/state you should re-synchronise on are reactive; things you merely want to read at the moment something happens are non-reactive.
Clarifying questions expected:
- "Which of these values should cause a reconnect, and which are just read at connect time?" — that question is the answer.
Code / implementation expected: Yes — the chat-room example with a reactive room and a non-reactive theme.