Trying to use Rich’s decision matrix to make, well, a decision. What a great method!
Wouldn’t it be an option to include the lifecycle methods into the options map of a ui element?:
(defn timer []
(let [state (atom 0)]
[col {:on-mount #(,,,)
:on-unmount #(,,,)}
,,,]))
It would be somewhat familiar to frontend (Hiccup, HTML), still uses Clojure style concepts, arrays will be an option for multiple hooks as well, captures local variables, has no special rules, and probably no runtime overhead (guessing from last variant).
Also you could keep it simple and omit the opts map if you don’t need it or include it as the first argument if you extend an existing component.
The other options look like a more complex rewrite, if someone later decides to add interaction to a static component.Definitely. I've had a similar experience when I've tried this method on difficult decisions in the project I've been working on. It really helps clarify my thinking in a way that also makes it easy to explain how I made my decision to others.
I too have used this to great effect since watching his talk 🙂
in "combining multiple hooks" I would also consider:
(defn use-fetch ,,,)
(defn use-watch ,,,)
(defn use-foo
[,,,]
;; I want to use two `use-fetch` and a `use-watch` in this. How?
) Nested arrays I guess
Can I (humbly) ask which of Rich's talks this technique is from?
@stig328 https://www.youtube.com/watch?v=c5QF2HjHLSE the latest one 😉
@paul.hempel I feel that would be wrong place to put them. Callbacks belong to component, not to the markup inside it