[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"search-suggestions":44,"article-react-weekly-useeffectevent-stale-closures":92,"path-membership-react-weekly-useeffectevent-stale-closures":475,"related-react-weekly-useeffectevent-stale-closures":476,"code:jsx:true:15pas05":593,"code:jsx:true:1qrdpgl":594,"code:jsx:true:1l97iar":595,"code:jsx:true:13eci1v":596,"code:jsx:true:1mva5p0":597,"comments-01a13e2e-d5ae-707f-a6c5-726f2ed01ab0":598},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,[45,49,53,57,61,65,69,73,77,80,84,88],{"slug":46,"name":47,"articles":48},"webdev","Webdev",178,{"slug":50,"name":51,"articles":52},"javascript","Javascript",142,{"slug":54,"name":55,"articles":56},"frontend","Frontend",99,{"slug":58,"name":59,"articles":60},"tutorial","Tutorial",74,{"slug":62,"name":63,"articles":64},"css","Css",54,{"slug":66,"name":67,"articles":68},"performance","Performance",31,{"slug":70,"name":71,"articles":72},"typescript","Typescript",26,{"slug":74,"name":75,"articles":76},"react","React",20,{"slug":78,"name":79,"articles":76},"programming","Programming",{"slug":81,"name":82,"articles":83},"browser","Browser",18,{"slug":85,"name":86,"articles":87},"node","Node",17,{"slug":89,"name":90,"articles":91},"html","Html",12,{"id":93,"slug":94,"title":95,"subtitle":96,"excerpt":97,"coverUrl":98,"locale":13,"readingMinutes":99,"publishedAt":100,"viewCount":101,"likeCount":19,"commentCount":19,"author":102,"vertical":107,"topic":108,"tags":109,"_count":114,"playground":116,"body":118,"bodyMd":424,"seo":425,"translationGroupId":427,"series":428,"podcastUrl":96,"verticalId":5,"thread":464,"assessments":466,"translations":471,"quiz":473},"01a13e2e-d5ae-707f-a6c5-726f2ed01ab0","react-weekly-useeffectevent-stale-closures","React 19.2 useEffectEvent: Why It Won't Fix Your Deps Array",null,"React's useEffectEvent (stable in 19.2) kills stale closures in Effects without a ref trick — but it's not a deps-array shortcut. Guide + cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-useeffectevent-stale-closures.png",15,"2026-10-17T12:20:57.469Z",418,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[110,111,112,113],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":58,"name":59,"color":96},{"slug":46,"name":47,"color":96},{"assessments":115},1,{"slug":94,"title":117},"useEffectEvent vs the deps array — interactive playground",{"blocks":119,"version":115},[120,124,127,130,133,138,141,150,153,156,159,172,175,178,184,187,192,195,198,201,204,207,210,213,217,220,223,226,229,233,236,239,242,245,248,251,254,257,260,264,267,270,279,282,289,292,296,299,302,305,308,311,315,318,321,324,327,355,359,362,370,373,376,379,382,385,388,391,394,397,400,406,409,412,415,418],{"id":121,"html":122,"type":123},"b1","\u003Cp>Your chat room component reconnects every time someone flips the dark-mode switch. Messages in flight get dropped, the &quot;typing…&quot; indicator resets, and support tickets call it &quot;random.&quot; The bug isn&#39;t the dark-mode toggle — it&#39;s that \u003Ccode>theme\u003C\u002Fcode> is sitting in a \u003Ccode>useEffect\u003C\u002Fcode> dependency array next to \u003Ccode>roomId\u003C\u002Fcode>, and React has no way to know that only one of those two values should actually restart the connection.\u003C\u002Fp>","paragraph",{"id":125,"html":126,"type":123},"b2","\u003Cp>The reflex fix — deleting \u003Ccode>theme\u003C\u002Fcode> from the array and silencing the lint warning — trades one bug for a worse one: the notification that fires on connect now shows whatever theme was active the moment the connection opened, forever, no matter how many times the user flips the switch afterward. That&#39;s a stale closure, and it&#39;s the single most common \u003Ccode>useEffect\u003C\u002Fcode> bug there is.\u003C\u002Fp>",{"id":128,"html":129,"type":123},"b3","\u003Cp>\u003Cstrong>React 19.2 (released October 1, 2025) shipped a real fix: the \u003Ccode>useEffectEvent\u003C\u002Fcode> Hook.\u003C\u002Fstrong> It lets an Effect read a value&#39;s \u003Cem>current\u003C\u002Fem> state without that value forcing the Effect to re-run — something no combination of dependency-array tricks could do safely before. This article covers what \u003Ccode>useEffectEvent\u003C\u002Fcode> actually does, the exact rules for using it, and the one way people keep misusing it that makes things worse, not better.\u003C\u002Fp>",{"id":131,"html":132,"type":123},"b4","\u003Cp>This article is written against \u003Cstrong>React 19.2+ \u002F 19.3.0\u003C\u002Fstrong> (verified against the current npm \u003Ccode>latest\u003C\u002Fcode> dist-tag for \u003Ccode>react\u003C\u002Fcode> and cross-checked coverage of the official 19.2 release notes and the React docs&#39; &quot;Separating Events from Effects&quot; guide; \u003Ccode>react.dev\u003C\u002Fcode> itself was unreachable from this run&#39;s network, so claims here lean on the npm registry plus multiple independent write-ups of the same release). \u003Ccode>useEffectEvent\u003C\u002Fcode> requires React 19.2 or later and assumes React 19-era function components and hooks throughout.\u003C\u002Fp>",{"id":134,"html":135,"text":136,"type":137,"level":31},"b5","What you&#39;ll learn","What you'll learn","heading",{"id":139,"html":140,"type":123},"b6","\u003Cp>By the end of this article you&#39;ll be able to:\u003C\u002Fp>",{"id":142,"type":143,"items":144,"ordered":18},"b7","list",[145,146,147,148,149],"Explain the real difference between a value an Effect must \u003Cem>depend on\u003C\u002Fem> and a value an Effect only needs to \u003Cem>read the latest copy of\u003C\u002Fem>","Reproduce the stale-closure bug that &quot;just remove it from the deps array&quot; causes, and name why it happens","Extract non-reactive logic out of an Effect with \u003Ccode>useEffectEvent\u003C\u002Fcode> and call it correctly","List the hard rules — where it can be called, what it can&#39;t be passed to, why it&#39;s excluded from the dependency array — and what breaks if you ignore them","Recognize when \u003Ccode>useEffectEvent\u003C\u002Fcode> is the wrong tool, because the value genuinely should resynchronize the Effect",{"id":151,"html":152,"text":152,"type":137,"level":31},"b8","Who this is for",{"id":154,"html":155,"type":123},"b9","\u003Cp>You&#39;ve written a \u003Ccode>useEffect\u003C\u002Fcode> with a dependency array, you&#39;ve seen the \u003Ccode>react-hooks\u002Fexhaustive-deps\u003C\u002Fcode> lint warning, and you&#39;ve been tempted to either silence it or just add everything it asks for. No class components or Server Components knowledge required.\u003C\u002Fp>",{"id":157,"html":158,"text":158,"type":137,"level":31},"b10","Table of contents",{"id":160,"type":143,"items":161,"ordered":18},"b11",[162,163,164,165,166,167,168,169,170,171],"\u003Ca href=\"#the-problem-one-dependency-array-two-different-jobs\">The problem: one dependency array, two different jobs\u003C\u002Fa>","\u003Ca href=\"#the-mental-model-reactive-values-vs-effect-events\">The mental model: reactive values vs. Effect Events\u003C\u002Fa>","\u003Ca href=\"#stage-1-the-naive-fix-and-its-stale-closure\">Stage 1 — the naive fix and its stale closure\u003C\u002Fa>","\u003Ca href=\"#stage-2-useeffecteffect-correctly\">Stage 2 — useEffectEvent, correctly\u003C\u002Fa>","\u003Ca href=\"#stage-3-more-than-one-effect-event\">Stage 3 — more than one Effect Event\u003C\u002Fa>","\u003Ca href=\"#edge-cases-and-gotchas\">Edge cases and gotchas\u003C\u002Fa>","\u003Ca href=\"#best-practices\">Best practices\u003C\u002Fa>","\u003Ca href=\"#faq\">FAQ\u003C\u002Fa>","\u003Ca href=\"#cheat-sheet\">Cheat sheet\u003C\u002Fa>","\u003Ca href=\"#key-takeaways\">Key takeaways\u003C\u002Fa>",{"id":173,"html":174,"text":174,"type":137,"level":31},"b12","The problem: one dependency array, two different jobs",{"id":176,"html":177,"type":123},"b13","\u003Cp>Here&#39;s the chat room, written the obvious way:\u003C\u002Fp>",{"id":179,"code":180,"type":181,"language":182,"highlight":183},"b14","function ChatRoom({ roomId, theme }) {\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => {\n      showNotification(\"Connected!\", theme);\n    });\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId, theme]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}","code","jsx",[],{"id":185,"html":186,"type":123},"b15","\u003Cp>\u003Ccode>react-hooks\u002Fexhaustive-deps\u003C\u002Fcode> is doing its job here: the Effect reads both \u003Ccode>roomId\u003C\u002Fcode> and \u003Ccode>theme\u003C\u002Fcode>, so both are listed. The code is &quot;correct&quot; by the lint rule&#39;s own standard. It&#39;s also wrong in a way the lint rule has no way to catch, because the rule only knows one move — \u003Cem>list everything you read\u003C\u002Fem> — and that move doesn&#39;t distinguish between two genuinely different jobs a value can have inside an Effect:\u003C\u002Fp>",{"id":188,"type":143,"items":189,"ordered":17},"b16",[190,191],"\u003Cstrong>\u003Ccode>roomId\u003C\u002Fcode> decides what the Effect \u003Cem>does\u003C\u002Fem>.\u003C\u002Fstrong> A different room means a different connection. If \u003Ccode>roomId\u003C\u002Fcode> changes and the Effect doesn&#39;t re-run, you&#39;re connected to the wrong room. This is a \u003Cstrong>reactive value\u003C\u002Fstrong> — the Effect&#39;s whole reason for existing is synchronized to it.","\u003Cstrong>\u003Ccode>theme\u003C\u002Fcode> is only \u003Cem>read\u003C\u002Fem> once the connection is already open\u003C\u002Fstrong>, to decide what the notification looks like. It has no bearing on which room you connect to. Listing it as a dependency doesn&#39;t make the code more correct — it makes the Effect re-run (disconnect, then reconnect) for a reason that has nothing to do with what the Effect is for.",{"id":193,"html":194,"type":123},"b17","\u003Cp>Toggle dark mode in this version and the user drops their connection. Not because anything about the connection needed to change — because the lint rule, correctly, cannot tell the difference between &quot;this value controls what the Effect synchronizes with&quot; and &quot;this value is read once a thing the Effect already started happens to fire.&quot;\u003C\u002Fp>",{"id":196,"html":197,"text":197,"type":137,"level":31},"b18","The mental model: reactive values vs. Effect Events",{"id":199,"html":200,"type":123},"b19","\u003Cp>\u003Cstrong>The mental model:\u003C\u002Fstrong> a \u003Ccode>useEffect\u003C\u002Fcode> dependency array isn&#39;t a list of &quot;everything this function touches&quot; — it&#39;s a list of \u003Cstrong>reactive values the Effect&#39;s job depends on\u003C\u002Fstrong>. If a value changing should legitimately restart what the Effect is doing, it belongs in the array, full stop; that&#39;s not a style choice, it&#39;s correctness. But some reads inside an Effect aren&#39;t about \u003Cem>what the Effect is doing\u003C\u002Fem> at all — they&#39;re about \u003Cem>what to do when something the Effect already set up happens later\u003C\u002Fem>. React 19.2 gives that second category a name — an \u003Cstrong>Effect Event\u003C\u002Fstrong> — and a Hook to create one: \u003Ccode>useEffectEvent\u003C\u002Fcode>.\u003C\u002Fp>",{"id":202,"html":203,"type":123},"b20","\u003Cp>An Effect Event is a function, declared with \u003Ccode>useEffectEvent(fn)\u003C\u002Fcode>, whose body is deliberately \u003Cstrong>non-reactive\u003C\u002Fstrong>: every time your component re-renders, React relinks the function to that render&#39;s latest props and state, but the function itself is never a dependency and never forces anything to re-run. You call it \u003Cem>from inside\u003C\u002Fem> an Effect (or from inside another Effect Event) when the thing it does should happen using \u003Cstrong>whatever is current right now\u003C\u002Fstrong>, not whatever was current when the Effect last ran.\u003C\u002Fp>",{"id":205,"html":206,"type":123},"b21","\u003Cp>Put plainly: \u003Ccode>roomId\u003C\u002Fcode> answers &quot;what should this Effect be connected to?&quot; — that&#39;s reactive, and it belongs in the array. \u003Ccode>theme\u003C\u002Fcode> answers &quot;what should happen, using today&#39;s value, when the thing I already connected to does something?&quot; — that&#39;s an Effect Event, and it has no business in the array at all.\u003C\u002Fp>",{"id":208,"html":209,"text":209,"type":137,"level":31},"b22","Stage 1 — the naive fix and its stale closure",{"id":211,"html":212,"type":123},"b23","\u003Cp>Before \u003Ccode>useEffectEvent\u003C\u002Fcode> existed, the common workaround was to simply drop \u003Ccode>theme\u003C\u002Fcode> from the array and disable the lint rule:\u003C\u002Fp>",{"id":214,"code":215,"type":181,"language":182,"highlight":216},"b24","function ChatRoom({ roomId, theme }) {\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => {\n      \u002F\u002F theme is captured from THIS render, forever, until roomId changes again\n      showNotification(\"Connected!\", theme);\n    });\n    connection.connect();\n    return () => connection.disconnect();\n    \u002F\u002F eslint-disable-next-line react-hooks\u002Fexhaustive-deps -- intentionally wrong, see below\n  }, [roomId]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}",[],{"id":218,"html":219,"type":123},"b25","\u003Cp>This stops the reconnect. It also freezes \u003Ccode>theme\u003C\u002Fcode> at whatever it was the moment the Effect last ran. JavaScript closures capture variables by reference to the scope they were created in, not by re-reading them later — so the \u003Ccode>theme\u003C\u002Fcode> inside \u003Ccode>connection.on(&quot;connected&quot;, …)\u003C\u002Fcode> is the one value from the render that created this particular closure. Flip dark mode ten times after that; the notification keeps showing the old theme until \u003Ccode>roomId\u003C\u002Fcode> changes and the whole Effect reruns. That&#39;s the stale closure: the code looks like it reads \u003Ccode>theme\u003C\u002Fcode>, but it&#39;s reading a frozen copy from the past.\u003C\u002Fp>",{"id":221,"html":222,"type":123},"b26","\u003Cp>This is the trap of &quot;just remove it from the deps array and silence the warning&quot;: you&#39;ve fixed the symptom (unwanted reconnects) by reintroducing the exact class of bug the lint rule exists to prevent (stale reads), just somewhere the rule can no longer see it.\u003C\u002Fp>",{"id":224,"html":225,"text":225,"type":137,"level":31},"b27","Stage 2 — useEffectEvent, correctly",{"id":227,"html":228,"type":123},"b28","\u003Cp>\u003Ccode>useEffectEvent\u003C\u002Fcode> splits the two jobs apart explicitly instead of hiding one of them:\u003C\u002Fp>",{"id":230,"code":231,"type":181,"language":182,"highlight":232},"b29","import { useEffect, useEffectEvent } from \"react\";\n\nfunction ChatRoom({ roomId, theme }) {\n  const onConnected = useEffectEvent(() => {\n    \u002F\u002F Always reads the CURRENT theme, no matter when this runs.\n    showNotification(\"Connected!\", theme);\n  });\n\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]); \u002F\u002F only roomId — and this time that's actually correct, not a lie\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}",[],{"id":234,"html":235,"type":123},"b30","\u003Cp>\u003Cstrong>Key concept:\u003C\u002Fstrong> \u003Ccode>onConnected\u003C\u002Fcode> is recreated on every render like any other local function, but calling it never reads a frozen snapshot — React always runs it against the component&#39;s latest props and state. Its identity is deliberately \u003Cem>not\u003C\u002Fem> stable across renders (unlike a \u003Ccode>useState\u003C\u002Fcode> setter or a \u003Ccode>useCallback\u003C\u002Fcode>-memoized function) — that&#39;s by design, so nothing can accidentally rely on it staying the same or pass it around like a normal callback. It simply can never legally appear in the dependency array in the first place, so the instability never causes a re-run. The Effect&#39;s dependency array now says something true: \u003Cem>this Effect only needs to re-run when \u003Ccode>roomId\u003C\u002Fcode> changes.\u003C\u002Fem> \u003Ccode>theme\u003C\u002Fcode> can change a thousand times without touching the connection, and the notification will still report whatever theme is active the instant it fires.\u003C\u002Fp>",{"id":237,"html":238,"type":123},"b31","\u003Cp>Toggle dark mode now: no disconnect, no reconnect, and the next notification shows the theme you just switched to. Both halves of the original bug — unwanted reconnects \u003Cem>and\u003C\u002Fem> stale reads — are gone, because they were never actually the same problem. They were two different values wearing one dependency array.\u003C\u002Fp>",{"id":240,"html":241,"type":123},"b32","\u003C!-- playground:start -->",{"id":243,"html":244,"text":244,"type":137,"level":31},"b33","🎮 Try it yourself",{"id":246,"html":247,"type":123},"b34","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-useeffectevent-stale-closures\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":249,"html":250,"type":123},"b35","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":252,"html":253,"type":123},"b36","\u003C!-- playground:end -->",{"id":255,"html":256,"text":256,"type":137,"level":31},"b37","Stage 3 — more than one Effect Event",{"id":258,"html":259,"type":123},"b38","\u003Cp>The pattern scales past a single notification. Say the chat room also has a mute toggle that should silence a &quot;ping&quot; sound without, again, reconnecting:\u003C\u002Fp>",{"id":261,"code":262,"type":181,"language":182,"highlight":263},"b39","function ChatRoom({ roomId, theme, isMuted }) {\n  const onConnected = useEffectEvent(() => {\n    showNotification(\"Connected!\", theme);\n  });\n\n  const onMessage = useEffectEvent((message) => {\n    if (!isMuted) playSound();\n    logMessage(message, theme);\n  });\n\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.on(\"message\", (msg) => onMessage(msg));\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]); \u002F\u002F roomId is the only reactive value here\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}",[],{"id":265,"html":266,"type":123},"b40","\u003Cp>\u003Cstrong>Key concept:\u003C\u002Fstrong> \u003Ccode>theme\u003C\u002Fcode> and \u003Ccode>isMuted\u003C\u002Fcode> can each change independently, as often as the user likes, and neither one is a dependency anywhere. The rule that decides what goes in \u003Ccode>useEffect\u003C\u002Fcode>&#39;s array hasn&#39;t changed — list every reactive value the Effect&#39;s \u003Cem>behavior\u003C\u002Fem> depends on — it&#39;s just that \u003Ccode>theme\u003C\u002Fcode> and \u003Ccode>isMuted\u003C\u002Fcode> were never one of those to begin with. They were Effect Event inputs all along; \u003Ccode>useEffectEvent\u003C\u002Fcode> just gives that distinction a real API instead of a lint-rule workaround.\u003C\u002Fp>",{"id":268,"html":269,"text":269,"type":137,"level":31},"b41","Edge cases and gotchas",{"id":271,"type":143,"items":272,"ordered":18},"b42",[273,274,275,276,277,278],"\u003Cstrong>You can only call an Effect Event from inside an Effect, or from inside another Effect Event.\u003C\u002Fstrong> Calling it during render, or handing it to a child component or another Hook as a prop, is not supported — \u003Ccode>eslint-plugin-react-hooks\u003C\u002Fcode> (6.1 and later; the current major is 7.x) flags both.","\u003Cstrong>It must be declared at the top level of a component or custom Hook\u003C\u002Fstrong>, like any other Hook — not inside a loop, condition, or nested function. If you need one per item in a list, pull that item into its own component.","\u003Cstrong>It cannot go in a dependency array.\u003C\u002Fstrong> You don&#39;t need to add it — the lint rule never asks you to — and if you add it anyway, a current \u003Ccode>eslint-plugin-react-hooks\u003C\u002Fcode> flags it directly (\u003Ccode>Functions returned from useEffectEvent must not be included in the dependency array\u003C\u002Fcode>) and tells you to remove it, because the whole point is that it isn&#39;t reactive.","\u003Cstrong>It is not a blanket fix for \u003Ccode>exhaustive-deps\u003C\u002Fcode> warnings.\u003C\u002Fstrong> If a value genuinely should restart the Effect — \u003Ccode>roomId\u003C\u002Fcode> in every example above — wrapping it in \u003Ccode>useEffectEvent\u003C\u002Fcode> to make the warning go away reintroduces the exact stale-closure bug Stage 1 showed, just with a newer API wrapped around it. The question to ask every time is &quot;should this value actually restart what the Effect is doing?&quot;, not &quot;how do I make the warning stop.&quot;","\u003Cstrong>It doesn&#39;t replace \u003Ccode>useRef\u003C\u002Fcode> for everything.\u003C\u002Fstrong> If you need to read a value from \u003Cem>outside\u003C\u002Fem> any Effect at all — say, inside a \u003Ccode>setTimeout\u003C\u002Fcode> callback registered by an event handler, not an Effect — \u003Ccode>useEffectEvent\u003C\u002Fcode>&#39;s restriction to Effects means a ref, or a plain callback prop, is still the right tool.","\u003Cstrong>Server Components never run Effects\u003C\u002Fstrong>, so this is purely a client-component concern; it doesn&#39;t change anything about the server\u002Fclient boundary.",{"id":280,"html":281,"text":281,"type":137,"level":31},"b43","Best practices",{"id":283,"type":143,"items":284,"ordered":18},"b44",[285,286,287,288],"\u003Cstrong>Reach for \u003Ccode>useEffectEvent\u003C\u002Fcode>\u003C\u002Fstrong> when an Effect&#39;s trigger condition should stay narrow (one connection per \u003Ccode>roomId\u003C\u002Fcode>) but an action it fires needs to use whatever is current at the moment it fires, not whatever was current when the Effect last started.","\u003Cstrong>Don&#39;t reach for it reflexively\u003C\u002Fstrong> every time \u003Ccode>exhaustive-deps\u003C\u002Fcode> complains. First ask whether the flagged value should actually resynchronize the Effect. If yes, keep it in the array — that&#39;s not friction, that&#39;s the rule doing its job.","\u003Cstrong>Keep Effect Events small and named for what they do\u003C\u002Fstrong> (\u003Ccode>onConnected\u003C\u002Fcode>, \u003Ccode>onMessage\u003C\u002Fcode>), not for what they avoid (\u003Ccode>stableTheme\u003C\u002Fcode>). The name should describe the moment it fires, because that&#39;s the mental model you&#39;re encoding.","\u003Cstrong>Pair it with a real connection\u002Fsubscription pattern\u003C\u002Fstrong>, not a one-off side effect. The value of splitting reactive setup from non-reactive reaction shows up most in Effects that stay alive across renders — connections, subscriptions, timers — not in an Effect that runs once and is done.",{"id":290,"html":291,"text":291,"type":137,"level":31},"b45","FAQ",{"id":293,"html":294,"text":295,"type":137,"level":43},"b46","Is \u003Ccode>useEffectEvent\u003C\u002Fcode> a replacement for \u003Ccode>useCallback\u003C\u002Fcode>?","Is useEffectEvent a replacement for useCallback?",{"id":297,"html":298,"type":123},"b47","\u003Cp>No. \u003Ccode>useCallback\u003C\u002Fcode> memoizes a function&#39;s \u003Cem>identity\u003C\u002Fem> across renders so a child doesn&#39;t re-render or a dependency array doesn&#39;t see a &quot;new&quot; function every time. \u003Ccode>useEffectEvent\u003C\u002Fcode> doesn&#39;t memoize for performance — it changes what the function is \u003Cem>allowed to see\u003C\u002Fem> (always-latest, never-reactive) and \u003Cem>where it can be called from\u003C\u002Fem> (only Effects and other Effect Events). They solve different problems and aren&#39;t interchangeable.\u003C\u002Fp>",{"id":300,"html":301,"text":301,"type":137,"level":43},"b48","Can I call an Effect Event from a click handler?",{"id":303,"html":304,"type":123},"b49","\u003Cp>No — an Effect Event can only be called from inside an Effect or another Effect Event, and the lint rule enforces this. If you need current-value behavior inside an \u003Ccode>onClick\u003C\u002Fcode>, you already have it: a normal event handler always closes over the latest render&#39;s values naturally, because it&#39;s recreated every render. The stale-closure problem this Hook solves is specific to long-lived Effects, not short-lived event handlers.\u003C\u002Fp>",{"id":306,"html":307,"text":307,"type":137,"level":43},"b50","Did this exist before React 19.2?",{"id":309,"html":310,"type":123},"b51","\u003Cp>Yes, behind an unstable name. It shipped for a long stretch as \u003Ccode>experimental_useEffectEvent\u003C\u002Fcode>, and the stabilized, unprefixed \u003Ccode>useEffectEvent\u003C\u002Fcode> landed in React 19.2 (October 2025). Code written against the experimental name needs the import updated, but the behavior and rules carried over.\u003C\u002Fp>",{"id":312,"html":313,"text":314,"type":137,"level":43},"b52","Does \u003Ccode>useEffectEvent\u003C\u002Fcode> need a special ESLint setup?","Does useEffectEvent need a special ESLint setup?",{"id":316,"html":317,"type":123},"b53","\u003Cp>You need a current \u003Ccode>eslint-plugin-react-hooks\u003C\u002Fcode> (6.1+; 7.x as of this writing) for the linter to correctly exclude Effect Event functions from dependency-array warnings instead of flagging them as missing. Without it, you&#39;ll fight the linter over something it already knows how to handle in a current version.\u003C\u002Fp>",{"id":319,"html":320,"text":320,"type":137,"level":43},"b54","What happens if I put the Effect Event function in the dependency array anyway?",{"id":322,"html":323,"type":123},"b55","\u003Cp>A current \u003Ccode>eslint-plugin-react-hooks\u003C\u002Fcode> flags it and tells you to remove it — it won&#39;t silently let it through. Functionally, adding it wouldn&#39;t do anything useful even if the linter allowed it: the function reference itself isn&#39;t what makes the behavior reactive or not. The reactivity question was never about the Effect Event&#39;s identity; it&#39;s about the values \u003Cem>inside\u003C\u002Fem> it, which are intentionally not tracked.\u003C\u002Fp>",{"id":325,"html":326,"text":326,"type":137,"level":31},"b56","Cheat sheet",{"id":328,"head":329,"rows":333,"type":354},"b57",[330,331,332],"Situation","What to do","Why",[334,338,342,346,350],[335,336,337],"A value decides \u003Cem>what\u003C\u002Fem> the Effect connects to \u002F sets up","Keep it in the dependency array","It&#39;s reactive — the Effect&#39;s job changes when it changes",[339,340,341],"A value is only read \u003Cem>after\u003C\u002Fem> something the Effect set up fires","Read it inside a \u003Ccode>useEffectEvent\u003C\u002Fcode>","Always current, never forces a re-run",[343,344,345],"Tempted to silence \u003Ccode>exhaustive-deps\u003C\u002Fcode> by deleting a dependency","Ask: should this value restart the Effect? If yes, keep it. If no, wrap the code that reads it in \u003Ccode>useEffectEvent\u003C\u002Fcode>","Deleting it silently reintroduces a stale closure",[347,348,349],"Need current-value behavior inside an \u003Ccode>onClick\u003C\u002Fcode>\u002F\u003Ccode>onChange\u003C\u002Fcode>","Do nothing special","Event handlers already close over the latest render",[351,352,353],"Need current-value behavior inside a \u003Ccode>setTimeout\u003C\u002Fcode> set up outside any Effect","Use a ref","\u003Ccode>useEffectEvent\u003C\u002Fcode> only works from inside Effects","table",{"id":356,"code":357,"type":181,"language":182,"highlight":358},"b58","import { useEffect, useEffectEvent } from \"react\";\n\nfunction ChatRoom({ roomId, theme, isMuted }) {\n  \u002F\u002F Non-reactive reads live here — never in the deps array, never the trigger.\n  const onConnected = useEffectEvent(() => {\n    showNotification(\"Connected!\", theme);\n  });\n\n  useEffect(() => {\n    \u002F\u002F Only truly reactive values live here.\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}",[],{"id":360,"html":361,"text":361,"type":137,"level":31},"b59","Key takeaways",{"id":363,"type":143,"items":364,"ordered":18},"b60",[365,366,367,368,369],"A \u003Ccode>useEffect\u003C\u002Fcode> dependency array lists \u003Cstrong>reactive values the Effect&#39;s job depends on\u003C\u002Fstrong> — not every value the Effect&#39;s body happens to read.","Deleting a value from the array to stop an unwanted re-run reintroduces a \u003Cstrong>stale closure\u003C\u002Fstrong>: the deleted value gets frozen at whatever it was when the Effect last ran.","\u003Cstrong>\u003Ccode>useEffectEvent\u003C\u002Fcode>\u003C\u002Fstrong> (stable since React 19.2, October 2025) gives non-reactive reads a real home: the function always sees the latest props\u002Fstate, but it&#39;s never a dependency and never retriggers the Effect.","It can only be called from inside an Effect or another Effect Event — never during render, never passed to a child or another Hook.","It is not a workaround for \u003Ccode>exhaustive-deps\u003C\u002Fcode> — if a value should genuinely resynchronize the Effect, it still belongs in the array.",{"id":371,"html":372,"type":123},"b61","\u003C!-- quiz:start -->",{"id":374,"html":375,"text":375,"type":137,"level":31},"b62","🧠 Test yourself",{"id":377,"html":378,"type":123},"b63","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-useeffectevent-stale-closures\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":380,"html":381,"type":123},"b64","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":383,"html":384,"type":123},"b65","\u003C!-- quiz:end -->",{"id":386,"html":387,"type":123},"b66","\u003Cp>That chat room from the opening scene now reconnects exactly when it should — when the room changes — and never when someone just prefers a darker screen. The bug was never really about dark mode; it was two different questions hiding inside one dependency array, and \u003Ccode>useEffectEvent\u003C\u002Fcode> is what finally lets you answer them separately.\u003C\u002Fp>",{"id":389,"html":390,"type":123},"b67","\u003Cp>If \u003Ca href=\"https:\u002F\u002Fdev.to\u002Fparsajiravand\u002Freact-derived-state-why-that-usestate-is-probably-a-bug-37h0\">\u003Ccode>React Derived State\u003C\u002Fcode>\u003C\u002Fa> taught you that an Effect syncing one piece of state into another is usually a bug, this is the companion lesson for the Effects you \u003Cem>do\u003C\u002Fem> need: not every value they read is there for the same reason, and now there&#39;s a real API for telling them apart. And if \u003Ca href=\"https:\u002F\u002Fdev.to\u002Fparsajiravand\u002Freact-re-render-vs-remount-what-actually-triggers-each-5fok\">\u003Ccode>Re-render vs Remount\u003C\u002Fcode>\u003C\u002Fa> taught you that \u003Ccode>key\u003C\u002Fcode> decides which component instance you&#39;re looking at, the same instinct applies here — \u003Ccode>roomId\u003C\u002Fcode> decides which \u003Cem>connection\u003C\u002Fem> you&#39;re looking at, and \u003Ccode>theme\u003C\u002Fcode> never should have.\u003C\u002Fp>",{"id":392,"html":393,"type":123},"b68","\u003Cp>Have you shipped a stale-closure bug from an Effect&#39;s dependency array — did you find it from a bug report, or from reading the code? Tell me below.\u003C\u002Fp>",{"id":395,"html":396,"type":123},"b69","\u003C!-- related:start -->",{"id":398,"html":399,"text":399,"type":137,"level":31},"b70","📚 Read next",{"id":401,"type":143,"items":402,"ordered":18},"b71",[403,404,405],"\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-derived-state-bug\">React Derived State: Why That useState Is Probably a Bug\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-viewtransition-component\">React 19.3 ViewTransition: Animate State Without Losing It\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-rerender-vs-remount\">React Re-render vs Remount: What Actually Triggers Each\u003C\u002Fa>",{"id":407,"html":408,"type":123},"b72","\u003C!-- related:end -->",{"id":410,"type":411},"b73","divider",{"id":413,"html":414,"type":123},"b74","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":416,"html":417,"type":123},"b75","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":419,"type":143,"items":420,"ordered":18},"b76",[421,422,423],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","Your chat room component reconnects every time someone flips the dark-mode switch. Messages in flight get dropped, the \"typing…\" indicator resets, and support tickets call it \"random.\" The bug isn't the dark-mode toggle — it's that `theme` is sitting in a `useEffect` dependency array next to `roomId`, and React has no way to know that only one of those two values should actually restart the connection.\n\nThe reflex fix — deleting `theme` from the array and silencing the lint warning — trades one bug for a worse one: the notification that fires on connect now shows whatever theme was active the moment the connection opened, forever, no matter how many times the user flips the switch afterward. That's a stale closure, and it's the single most common `useEffect` bug there is.\n\n**React 19.2 (released October 1, 2025) shipped a real fix: the `useEffectEvent` Hook.** It lets an Effect read a value's *current* state without that value forcing the Effect to re-run — something no combination of dependency-array tricks could do safely before. This article covers what `useEffectEvent` actually does, the exact rules for using it, and the one way people keep misusing it that makes things worse, not better.\n\nThis article is written against **React 19.2+ \u002F 19.3.0** (verified against the current npm `latest` dist-tag for `react` and cross-checked coverage of the official 19.2 release notes and the React docs' \"Separating Events from Effects\" guide; `react.dev` itself was unreachable from this run's network, so claims here lean on the npm registry plus multiple independent write-ups of the same release). `useEffectEvent` requires React 19.2 or later and assumes React 19-era function components and hooks throughout.\n\n## What you'll learn\n\nBy the end of this article you'll be able to:\n\n- Explain the real difference between a value an Effect must *depend on* and a value an Effect only needs to *read the latest copy of*\n- Reproduce the stale-closure bug that \"just remove it from the deps array\" causes, and name why it happens\n- Extract non-reactive logic out of an Effect with `useEffectEvent` and call it correctly\n- List the hard rules — where it can be called, what it can't be passed to, why it's excluded from the dependency array — and what breaks if you ignore them\n- Recognize when `useEffectEvent` is the wrong tool, because the value genuinely should resynchronize the Effect\n\n## Who this is for\n\nYou've written a `useEffect` with a dependency array, you've seen the `react-hooks\u002Fexhaustive-deps` lint warning, and you've been tempted to either silence it or just add everything it asks for. No class components or Server Components knowledge required.\n\n## Table of contents\n\n- [The problem: one dependency array, two different jobs](#the-problem-one-dependency-array-two-different-jobs)\n- [The mental model: reactive values vs. Effect Events](#the-mental-model-reactive-values-vs-effect-events)\n- [Stage 1 — the naive fix and its stale closure](#stage-1-the-naive-fix-and-its-stale-closure)\n- [Stage 2 — useEffectEvent, correctly](#stage-2-useeffecteffect-correctly)\n- [Stage 3 — more than one Effect Event](#stage-3-more-than-one-effect-event)\n- [Edge cases and gotchas](#edge-cases-and-gotchas)\n- [Best practices](#best-practices)\n- [FAQ](#faq)\n- [Cheat sheet](#cheat-sheet)\n- [Key takeaways](#key-takeaways)\n\n## The problem: one dependency array, two different jobs\n\nHere's the chat room, written the obvious way:\n\n```jsx\nfunction ChatRoom({ roomId, theme }) {\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => {\n      showNotification(\"Connected!\", theme);\n    });\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId, theme]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}\n```\n\n`react-hooks\u002Fexhaustive-deps` is doing its job here: the Effect reads both `roomId` and `theme`, so both are listed. The code is \"correct\" by the lint rule's own standard. It's also wrong in a way the lint rule has no way to catch, because the rule only knows one move — *list everything you read* — and that move doesn't distinguish between two genuinely different jobs a value can have inside an Effect:\n\n1. **`roomId` decides what the Effect *does*.** A different room means a different connection. If `roomId` changes and the Effect doesn't re-run, you're connected to the wrong room. This is a **reactive value** — the Effect's whole reason for existing is synchronized to it.\n2. **`theme` is only *read* once the connection is already open**, to decide what the notification looks like. It has no bearing on which room you connect to. Listing it as a dependency doesn't make the code more correct — it makes the Effect re-run (disconnect, then reconnect) for a reason that has nothing to do with what the Effect is for.\n\nToggle dark mode in this version and the user drops their connection. Not because anything about the connection needed to change — because the lint rule, correctly, cannot tell the difference between \"this value controls what the Effect synchronizes with\" and \"this value is read once a thing the Effect already started happens to fire.\"\n\n## The mental model: reactive values vs. Effect Events\n\n**The mental model:** a `useEffect` dependency array isn't a list of \"everything this function touches\" — it's a list of **reactive values the Effect's job depends on**. If a value changing should legitimately restart what the Effect is doing, it belongs in the array, full stop; that's not a style choice, it's correctness. But some reads inside an Effect aren't about *what the Effect is doing* at all — they're about *what to do when something the Effect already set up happens later*. React 19.2 gives that second category a name — an **Effect Event** — and a Hook to create one: `useEffectEvent`.\n\nAn Effect Event is a function, declared with `useEffectEvent(fn)`, whose body is deliberately **non-reactive**: every time your component re-renders, React relinks the function to that render's latest props and state, but the function itself is never a dependency and never forces anything to re-run. You call it *from inside* an Effect (or from inside another Effect Event) when the thing it does should happen using **whatever is current right now**, not whatever was current when the Effect last ran.\n\nPut plainly: `roomId` answers \"what should this Effect be connected to?\" — that's reactive, and it belongs in the array. `theme` answers \"what should happen, using today's value, when the thing I already connected to does something?\" — that's an Effect Event, and it has no business in the array at all.\n\n## Stage 1 — the naive fix and its stale closure\n\nBefore `useEffectEvent` existed, the common workaround was to simply drop `theme` from the array and disable the lint rule:\n\n```jsx\nfunction ChatRoom({ roomId, theme }) {\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => {\n      \u002F\u002F theme is captured from THIS render, forever, until roomId changes again\n      showNotification(\"Connected!\", theme);\n    });\n    connection.connect();\n    return () => connection.disconnect();\n    \u002F\u002F eslint-disable-next-line react-hooks\u002Fexhaustive-deps -- intentionally wrong, see below\n  }, [roomId]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}\n```\n\nThis stops the reconnect. It also freezes `theme` at whatever it was the moment the Effect last ran. JavaScript closures capture variables by reference to the scope they were created in, not by re-reading them later — so the `theme` inside `connection.on(\"connected\", …)` is the one value from the render that created this particular closure. Flip dark mode ten times after that; the notification keeps showing the old theme until `roomId` changes and the whole Effect reruns. That's the stale closure: the code looks like it reads `theme`, but it's reading a frozen copy from the past.\n\nThis is the trap of \"just remove it from the deps array and silence the warning\": you've fixed the symptom (unwanted reconnects) by reintroducing the exact class of bug the lint rule exists to prevent (stale reads), just somewhere the rule can no longer see it.\n\n## Stage 2 — useEffectEvent, correctly\n\n`useEffectEvent` splits the two jobs apart explicitly instead of hiding one of them:\n\n```jsx\nimport { useEffect, useEffectEvent } from \"react\";\n\nfunction ChatRoom({ roomId, theme }) {\n  const onConnected = useEffectEvent(() => {\n    \u002F\u002F Always reads the CURRENT theme, no matter when this runs.\n    showNotification(\"Connected!\", theme);\n  });\n\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]); \u002F\u002F only roomId — and this time that's actually correct, not a lie\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}\n```\n\n**Key concept:** `onConnected` is recreated on every render like any other local function, but calling it never reads a frozen snapshot — React always runs it against the component's latest props and state. Its identity is deliberately *not* stable across renders (unlike a `useState` setter or a `useCallback`-memoized function) — that's by design, so nothing can accidentally rely on it staying the same or pass it around like a normal callback. It simply can never legally appear in the dependency array in the first place, so the instability never causes a re-run. The Effect's dependency array now says something true: *this Effect only needs to re-run when `roomId` changes.* `theme` can change a thousand times without touching the connection, and the notification will still report whatever theme is active the instant it fires.\n\nToggle dark mode now: no disconnect, no reconnect, and the next notification shows the theme you just switched to. Both halves of the original bug — unwanted reconnects *and* stale reads — are gone, because they were never actually the same problem. They were two different values wearing one dependency array.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-useeffectevent-stale-closures\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## Stage 3 — more than one Effect Event\n\nThe pattern scales past a single notification. Say the chat room also has a mute toggle that should silence a \"ping\" sound without, again, reconnecting:\n\n```jsx\nfunction ChatRoom({ roomId, theme, isMuted }) {\n  const onConnected = useEffectEvent(() => {\n    showNotification(\"Connected!\", theme);\n  });\n\n  const onMessage = useEffectEvent((message) => {\n    if (!isMuted) playSound();\n    logMessage(message, theme);\n  });\n\n  useEffect(() => {\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.on(\"message\", (msg) => onMessage(msg));\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]); \u002F\u002F roomId is the only reactive value here\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}\n```\n\n**Key concept:** `theme` and `isMuted` can each change independently, as often as the user likes, and neither one is a dependency anywhere. The rule that decides what goes in `useEffect`'s array hasn't changed — list every reactive value the Effect's *behavior* depends on — it's just that `theme` and `isMuted` were never one of those to begin with. They were Effect Event inputs all along; `useEffectEvent` just gives that distinction a real API instead of a lint-rule workaround.\n\n## Edge cases and gotchas\n\n- **You can only call an Effect Event from inside an Effect, or from inside another Effect Event.** Calling it during render, or handing it to a child component or another Hook as a prop, is not supported — `eslint-plugin-react-hooks` (6.1 and later; the current major is 7.x) flags both.\n- **It must be declared at the top level of a component or custom Hook**, like any other Hook — not inside a loop, condition, or nested function. If you need one per item in a list, pull that item into its own component.\n- **It cannot go in a dependency array.** You don't need to add it — the lint rule never asks you to — and if you add it anyway, a current `eslint-plugin-react-hooks` flags it directly (`Functions returned from useEffectEvent must not be included in the dependency array`) and tells you to remove it, because the whole point is that it isn't reactive.\n- **It is not a blanket fix for `exhaustive-deps` warnings.** If a value genuinely should restart the Effect — `roomId` in every example above — wrapping it in `useEffectEvent` to make the warning go away reintroduces the exact stale-closure bug Stage 1 showed, just with a newer API wrapped around it. The question to ask every time is \"should this value actually restart what the Effect is doing?\", not \"how do I make the warning stop.\"\n- **It doesn't replace `useRef` for everything.** If you need to read a value from *outside* any Effect at all — say, inside a `setTimeout` callback registered by an event handler, not an Effect — `useEffectEvent`'s restriction to Effects means a ref, or a plain callback prop, is still the right tool.\n- **Server Components never run Effects**, so this is purely a client-component concern; it doesn't change anything about the server\u002Fclient boundary.\n\n## Best practices\n\n- **Reach for `useEffectEvent`** when an Effect's trigger condition should stay narrow (one connection per `roomId`) but an action it fires needs to use whatever is current at the moment it fires, not whatever was current when the Effect last started.\n- **Don't reach for it reflexively** every time `exhaustive-deps` complains. First ask whether the flagged value should actually resynchronize the Effect. If yes, keep it in the array — that's not friction, that's the rule doing its job.\n- **Keep Effect Events small and named for what they do** (`onConnected`, `onMessage`), not for what they avoid (`stableTheme`). The name should describe the moment it fires, because that's the mental model you're encoding.\n- **Pair it with a real connection\u002Fsubscription pattern**, not a one-off side effect. The value of splitting reactive setup from non-reactive reaction shows up most in Effects that stay alive across renders — connections, subscriptions, timers — not in an Effect that runs once and is done.\n\n## FAQ\n\n### Is `useEffectEvent` a replacement for `useCallback`?\n\nNo. `useCallback` memoizes a function's *identity* across renders so a child doesn't re-render or a dependency array doesn't see a \"new\" function every time. `useEffectEvent` doesn't memoize for performance — it changes what the function is *allowed to see* (always-latest, never-reactive) and *where it can be called from* (only Effects and other Effect Events). They solve different problems and aren't interchangeable.\n\n### Can I call an Effect Event from a click handler?\n\nNo — an Effect Event can only be called from inside an Effect or another Effect Event, and the lint rule enforces this. If you need current-value behavior inside an `onClick`, you already have it: a normal event handler always closes over the latest render's values naturally, because it's recreated every render. The stale-closure problem this Hook solves is specific to long-lived Effects, not short-lived event handlers.\n\n### Did this exist before React 19.2?\n\nYes, behind an unstable name. It shipped for a long stretch as `experimental_useEffectEvent`, and the stabilized, unprefixed `useEffectEvent` landed in React 19.2 (October 2025). Code written against the experimental name needs the import updated, but the behavior and rules carried over.\n\n### Does `useEffectEvent` need a special ESLint setup?\n\nYou need a current `eslint-plugin-react-hooks` (6.1+; 7.x as of this writing) for the linter to correctly exclude Effect Event functions from dependency-array warnings instead of flagging them as missing. Without it, you'll fight the linter over something it already knows how to handle in a current version.\n\n### What happens if I put the Effect Event function in the dependency array anyway?\n\nA current `eslint-plugin-react-hooks` flags it and tells you to remove it — it won't silently let it through. Functionally, adding it wouldn't do anything useful even if the linter allowed it: the function reference itself isn't what makes the behavior reactive or not. The reactivity question was never about the Effect Event's identity; it's about the values *inside* it, which are intentionally not tracked.\n\n## Cheat sheet\n\n| Situation | What to do | Why |\n| --- | --- | --- |\n| A value decides *what* the Effect connects to \u002F sets up | Keep it in the dependency array | It's reactive — the Effect's job changes when it changes |\n| A value is only read *after* something the Effect set up fires | Read it inside a `useEffectEvent` | Always current, never forces a re-run |\n| Tempted to silence `exhaustive-deps` by deleting a dependency | Ask: should this value restart the Effect? If yes, keep it. If no, wrap the code that reads it in `useEffectEvent` | Deleting it silently reintroduces a stale closure |\n| Need current-value behavior inside an `onClick`\u002F`onChange` | Do nothing special | Event handlers already close over the latest render |\n| Need current-value behavior inside a `setTimeout` set up outside any Effect | Use a ref | `useEffectEvent` only works from inside Effects |\n\n```jsx\nimport { useEffect, useEffectEvent } from \"react\";\n\nfunction ChatRoom({ roomId, theme, isMuted }) {\n  \u002F\u002F Non-reactive reads live here — never in the deps array, never the trigger.\n  const onConnected = useEffectEvent(() => {\n    showNotification(\"Connected!\", theme);\n  });\n\n  useEffect(() => {\n    \u002F\u002F Only truly reactive values live here.\n    const connection = createConnection(roomId);\n    connection.on(\"connected\", () => onConnected());\n    connection.connect();\n    return () => connection.disconnect();\n  }, [roomId]);\n\n  return \u003Ch1>Welcome to {roomId}\u003C\u002Fh1>;\n}\n```\n\n## Key takeaways\n\n- A `useEffect` dependency array lists **reactive values the Effect's job depends on** — not every value the Effect's body happens to read.\n- Deleting a value from the array to stop an unwanted re-run reintroduces a **stale closure**: the deleted value gets frozen at whatever it was when the Effect last ran.\n- **`useEffectEvent`** (stable since React 19.2, October 2025) gives non-reactive reads a real home: the function always sees the latest props\u002Fstate, but it's never a dependency and never retriggers the Effect.\n- It can only be called from inside an Effect or another Effect Event — never during render, never passed to a child or another Hook.\n- It is not a workaround for `exhaustive-deps` — if a value should genuinely resynchronize the Effect, it still belongs in the array.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-useeffectevent-stale-closures\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\nThat chat room from the opening scene now reconnects exactly when it should — when the room changes — and never when someone just prefers a darker screen. The bug was never really about dark mode; it was two different questions hiding inside one dependency array, and `useEffectEvent` is what finally lets you answer them separately.\n\nIf [`React Derived State`](https:\u002F\u002Fdev.to\u002Fparsajiravand\u002Freact-derived-state-why-that-usestate-is-probably-a-bug-37h0) taught you that an Effect syncing one piece of state into another is usually a bug, this is the companion lesson for the Effects you *do* need: not every value they read is there for the same reason, and now there's a real API for telling them apart. And if [`Re-render vs Remount`](https:\u002F\u002Fdev.to\u002Fparsajiravand\u002Freact-re-render-vs-remount-what-actually-triggers-each-5fok) taught you that `key` decides which component instance you're looking at, the same instinct applies here — `roomId` decides which *connection* you're looking at, and `theme` never should have.\n\nHave you shipped a stale-closure bug from an Effect's dependency array — did you find it from a bug report, or from reading the code? Tell me below.\n\n\u003C!-- related:start -->\n\n## 📚 Read next\n\n- [React Derived State: Why That useState Is Probably a Bug](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-derived-state-bug)\n- [React 19.3 ViewTransition: Animate State Without Losing It](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-viewtransition-component)\n- [React Re-render vs Remount: What Actually Triggers Each](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-rerender-vs-remount)\n\n\u003C!-- related:end -->\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":95,"canonical":426,"description":97},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-weekly-useeffectevent-stale-closures","01a13e2e-d5ae-707f-a6c5-774b59813888",{"name":429,"part":430,"total":431,"items":432},"React Deep Dive",7,8,[433,438,442,446,451,455,459,460],{"slug":434,"title":435,"publishedAt":436,"readingMinutes":437},"react-weekly-rerender-vs-remount","React Re-render vs Remount: What Actually Triggers Each","2026-08-29T12:32:41.200Z",13,{"slug":439,"title":440,"publishedAt":441,"readingMinutes":437},"react-weekly-compiler-memoization","React Compiler 1.0: What useMemo You Can Delete","2026-09-05T10:17:49.849Z",{"slug":443,"title":444,"publishedAt":445,"readingMinutes":437},"react-weekly-form-actions-pending-state","React Form Actions: useActionState & useFormStatus Guide","2026-09-12T10:23:52.928Z",{"slug":447,"title":448,"publishedAt":449,"readingMinutes":450},"react-weekly-derived-state-bug","React Derived State: Why That useState Is Probably a Bug","2026-09-20T16:27:07.271Z",14,{"slug":452,"title":453,"publishedAt":454,"readingMinutes":99},"react-weekly-viewtransition-component","React 19.3 ViewTransition: Animate State Without Losing It","2026-10-03T11:22:26.437Z",{"slug":456,"title":457,"publishedAt":458,"readingMinutes":437},"react-weekly-fragment-refs","React 19.3 Fragment Refs: Skip the Wrapper Div for a Ref","2026-10-10T12:12:38.989Z",{"slug":94,"title":95,"publishedAt":100,"readingMinutes":99},{"slug":461,"title":462,"publishedAt":463,"readingMinutes":450},"react-weekly-activity-component","React Activity Component: The State Between Render and Remount","2026-11-02T06:10:18.569Z",{"id":465,"locked":18},"01a13e2e-d5fa-73e8-bb20-ec38be9be2d4",[467],{"id":468,"slug":94,"title":469,"_count":470},"01a13e2e-d61d-73fe-b743-8f0048764497","React useEffectEvent — test yourself",{"questions":431},[472],{"locale":13,"slug":94},{"id":468,"slug":94,"title":469,"_count":474,"questionCount":431},{"questions":431},[],{"items":477,"meta":592},[478,493,512,524,544,559,574],{"id":479,"slug":461,"title":462,"subtitle":96,"excerpt":480,"coverUrl":481,"locale":13,"readingMinutes":450,"publishedAt":463,"viewCount":482,"likeCount":19,"commentCount":19,"author":483,"vertical":484,"topic":485,"tags":486,"_count":491,"playground":492,"hasQuiz":17,"hasPlayground":17},"01a1623b-51e7-7669-89ad-eb54d67696eb","React's Activity component hides a subtree without unmounting it — what state, effects, and renders actually do, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-activity-component.png",407,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[487,488,489,490],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":58,"name":59,"color":96},{"slug":46,"name":47,"color":96},{"assessments":115},{"slug":461},{"id":494,"slug":495,"title":496,"subtitle":96,"excerpt":497,"coverUrl":498,"locale":13,"readingMinutes":499,"publishedAt":500,"viewCount":501,"likeCount":19,"commentCount":19,"author":502,"vertical":503,"topic":504,"tags":505,"_count":510,"playground":511,"hasQuiz":17,"hasPlayground":17},"01a14e81-eaa5-700a-a6f6-3be4ffe47c2b","usesyncexternalstore-tearing-fix","Your Custom Hooks Tear in React 18. `useSyncExternalStore` Fixes It.","A useState + useEffect hook that subscribes to window size, localStorage, or a WebSocket looks fine until React 18's concurrent rendering shows two parts of your UI two different values at once. useSyncExternalStore is the hook built to stop that.","\u002Fmedia\u002Fcovers\u002Fusesyncexternalstore-tearing-fix.png",5,"2026-10-23T06:11:03.306Z",433,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[506,507,508,509],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":46,"name":47,"color":96},{"slug":54,"name":55,"color":96},{"assessments":115},{"slug":495},{"id":93,"slug":94,"title":95,"subtitle":96,"excerpt":97,"coverUrl":98,"locale":13,"readingMinutes":99,"publishedAt":100,"viewCount":513,"likeCount":19,"commentCount":19,"author":514,"vertical":515,"topic":516,"tags":517,"_count":522,"playground":523,"hasQuiz":17,"hasPlayground":17},419,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[518,519,520,521],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":58,"name":59,"color":96},{"slug":46,"name":47,"color":96},{"assessments":115},{"slug":94},{"id":525,"slug":526,"title":527,"subtitle":96,"excerpt":528,"coverUrl":529,"locale":13,"readingMinutes":99,"publishedAt":530,"viewCount":531,"likeCount":19,"commentCount":19,"author":532,"vertical":533,"topic":534,"tags":537,"_count":542,"playground":543,"hasQuiz":17,"hasPlayground":17},"01a120b9-d611-74ef-ad15-a267677c3251","nextjs-weekly-image-priority-quality-changes","Next.js 16 Image: priority Deprecated, quality Now Allowlisted","Next.js 16 quietly deprecated Image's priority for preload and restricts quality to an allowlist (default: 75). What breaks, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fnextjs-weekly-image-priority-quality-changes.png","2026-10-13T06:10:29.815Z",819,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":535,"name":536},"nextjs","Nextjs",[538,539,540,541],{"slug":535,"name":536,"color":96},{"slug":74,"name":75,"color":96},{"slug":46,"name":47,"color":96},{"slug":58,"name":59,"color":96},{"assessments":115},{"slug":526},{"id":545,"slug":456,"title":457,"subtitle":96,"excerpt":546,"coverUrl":547,"locale":13,"readingMinutes":437,"publishedAt":458,"viewCount":548,"likeCount":19,"commentCount":19,"author":549,"vertical":550,"topic":551,"tags":552,"_count":557,"playground":558,"hasQuiz":17,"hasPlayground":17},"01a117e0-acb2-740f-9391-db919729cf21","React 19.3 Fragment Refs let you ref a sibling group with no wrapper div. Learn the FragmentInstance API, its limits, and get a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-fragment-refs.png",658,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[553,554,555,556],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":58,"name":59,"color":96},{"slug":46,"name":47,"color":96},{"assessments":115},{"slug":456},{"id":560,"slug":452,"title":453,"subtitle":96,"excerpt":561,"coverUrl":562,"locale":13,"readingMinutes":99,"publishedAt":454,"viewCount":563,"likeCount":19,"commentCount":19,"author":564,"vertical":565,"topic":566,"tags":567,"_count":572,"playground":573,"hasQuiz":17,"hasPlayground":17},"01a0f615-d2be-750b-839e-02fd75291b4e","React 19.3's ViewTransition component animates state changes, not just page swaps — the mental model, enter\u002Fexit\u002Fupdate\u002Fshare, and a cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-viewtransition-component.png",682,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[568,569,570,571],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":58,"name":59,"color":96},{"slug":46,"name":47,"color":96},{"assessments":115},{"slug":452},{"id":575,"slug":576,"title":577,"subtitle":96,"excerpt":578,"coverUrl":579,"locale":13,"readingMinutes":499,"publishedAt":580,"viewCount":581,"likeCount":19,"commentCount":19,"author":582,"vertical":583,"topic":584,"tags":585,"_count":590,"playground":591,"hasQuiz":17,"hasPlayground":17},"01a0ec73-247c-7738-84ae-80c9d1d116a8","input-lag-bug-debounce-cant-fix","Your Search Box Lags. Debounce Hides It; `useTransition` Fixes It","A big list re-render was blocking every keystroke — debouncing just moved the freeze. useTransition tells React which update can wait.","\u002Fmedia\u002Fcovers\u002Finput-lag-bug-debounce-cant-fix.png","2026-10-03T11:21:55.564Z",570,{"id":103,"name":104,"username":105,"avatarUrl":96,"headline":106},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":74,"name":75},[586,587,588,589],{"slug":74,"name":75,"color":96},{"slug":50,"name":51,"color":96},{"slug":46,"name":47,"color":96},{"slug":66,"name":67,"color":96},{"assessments":115},{"slug":576},{"page":115,"perPage":430,"total":76,"totalPages":43},"\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ChatRoom\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> connection \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createConnection\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"connected\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n      \u003Cspan class=\"shj-func\">showNotification\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"Connected!\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">connect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">disconnect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>Welcome to \u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ChatRoom\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> connection \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createConnection\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"connected\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n      \u003Cspan class=\"shj-cmnt\">\u002F\u002F theme is captured from THIS render, forever, until roomId changes again\n\u003C\u002Fspan>      \u003Cspan class=\"shj-func\">showNotification\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"Connected!\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">connect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">disconnect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-cmnt\">\u002F\u002F eslint-disable-next-line react-hooks\u002Fexhaustive-deps -- intentionally wrong, see below\n\u003C\u002Fspan>  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>Welcome to \u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> useEffect\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> useEffectEvent \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"react\"\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ChatRoom\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> onConnected \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useEffectEvent\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-cmnt\">\u002F\u002F Always reads the CURRENT theme, no matter when this runs.\n\u003C\u002Fspan>    \u003Cspan class=\"shj-func\">showNotification\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"Connected!\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> connection \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createConnection\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"connected\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">onConnected\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">connect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">disconnect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F only roomId — and this time that's actually correct, not a lie\n\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>Welcome to \u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003Cdiv>18\u003C\u002Fdiv>\u003Cdiv>19\u003C\u002Fdiv>\u003Cdiv>20\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ChatRoom\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> isMuted \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> onConnected \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useEffectEvent\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-func\">showNotification\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"Connected!\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> onMessage \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useEffectEvent\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>message\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">if\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">!\u003C\u002Fspan>isMuted\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-func\">playSound\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-func\">logMessage\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>message\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> connection \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createConnection\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"connected\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">onConnected\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"message\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>msg\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">onMessage\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>msg\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">connect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">disconnect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F roomId is the only reactive value here\n\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>Welcome to \u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003Cdiv>18\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> useEffect\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> useEffectEvent \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"react\"\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ChatRoom\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> roomId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> isMuted \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F Non-reactive reads live here — never in the deps array, never the trigger.\n\u003C\u002Fspan>  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> onConnected \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useEffectEvent\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-func\">showNotification\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"Connected!\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> theme\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-cmnt\">\u002F\u002F Only truly reactive values live here.\n\u003C\u002Fspan>    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> connection \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createConnection\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">on\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"connected\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">onConnected\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">connect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> connection\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">disconnect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>roomId\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>Welcome to \u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>roomId\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">h1\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":599},[]]