This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-09
Channels
- # announcements (3)
- # babashka (1)
- # beginners (66)
- # clj-kondo (2)
- # cljdoc (46)
- # cljs-dev (7)
- # clojure (16)
- # clojure-australia (2)
- # clojure-china (1)
- # clojure-europe (3)
- # clojure-hk (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-sg (1)
- # clojure-taiwan (1)
- # clojurescript (4)
- # community-development (53)
- # conjure (6)
- # css (7)
- # cursive (6)
- # datascript (1)
- # datomic (5)
- # exercism (5)
- # graalvm (12)
- # helix (8)
- # jobs-rus (1)
- # kaocha (1)
- # lsp (19)
- # nrepl (1)
- # overtone (2)
- # pedestal (1)
- # polylith (2)
- # portal (2)
- # react (25)
- # reagent (1)
- # shadow-cljs (7)
- # spacemacs (8)
- # vim (9)
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.