Fork me on GitHub

In the last week I've debugged both a with-let reactivity issue, and an issue where an external hooks component was blowing up because of duplicate copies of react getting pulled in. I thought I saw parallels that (might have?) helped me grok what's going on a bit better. Thought I'd share them in case they're helpful &/or to check if I'm subtly or completely incorrect. Roughly: based on my read of the with-let macro, when I call it I establish a cached reaction in a private associative data structure within reagent, keyed with a gensym by the macro at compile time so that reagent can give it back on re-render. With hooks, that's roughly what's happening too: a call to useState is establishing an entry in a data structure internal to React. In React's case, the entry is retrieved positionally instead of by key. A couple of explanations fall out of that. First, why hooks calls can't be in an if: it has to be a stable order over all re-renders. Second, why duplicate Reacts are bad: there are two possible places for the private data structure of hook state.