This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-24
Channels
- # announcements (1)
- # asami (10)
- # aws (1)
- # babashka (1)
- # beginners (105)
- # cider (13)
- # cljsrn (6)
- # clojure (42)
- # clojure-australia (4)
- # clojure-dev (7)
- # clojure-europe (26)
- # clojure-nl (2)
- # clojure-uk (13)
- # clojurescript (19)
- # code-reviews (3)
- # conjure (18)
- # core-async (4)
- # core-matrix (5)
- # cryogen (3)
- # datomic (27)
- # depstar (21)
- # emacs (2)
- # figwheel-main (9)
- # fulcro (18)
- # helix (7)
- # jobs (3)
- # jobs-discuss (15)
- # juxt (7)
- # kaocha (4)
- # lambdaisland (2)
- # leiningen (11)
- # luminus (1)
- # malli (6)
- # meander (9)
- # minimallist (4)
- # mount (3)
- # off-topic (3)
- # pathom (8)
- # pedestal (28)
- # rdf (13)
- # re-frame (7)
- # reagent (5)
- # shadow-cljs (3)
Would it make sense to add support for custom equality fns to use-effect, use-memo, etc? I'm in a situation now where I want to run an effect when a list of vectors changes, which as far as I can tell requires me to pull in/write something like https://github.com/kotarella1110/use-custom-compare.
we have a hook at work that we call use-stable-identity
, which you can use like:
(hooks/use-effect
[(use-stable-identity foo) bar baz]
,,,)
when you really need to do a deep comparison of valuesthis still doesn't cover the most annoying cases like, constructing a new Date
or something 😓
I've thought about adding this to helix. I wouldn't add this to use-effect
/ use-memo
though, but rather have it as a separate hook so you can opt in
@lilactown Yes I am, and I see now I don't have to. Thanks. For reference, a naive impl of custom equality for use-effect is pretty simple:
(defn use-custom-compare-memoize [deps eq?]
(let [ref (h.hooks/use-ref [])]
(if (or (not @ref) (not (eq? @ref deps)))
(reset! ref deps))
(into-array @ref)))
(defn use-custom-compare-effect [effect deps eq?]
(react/useEffect effect (use-custom-compare-memoize deps eq?)))