Is it stupid to just (hash a-bunch-of-things)
if I want to trigger the effect to re-run whenever a-bunch-of-things
change?
IIRC there are times when hash
will return a different number for the same value. it would be ideal for something that's best effort
what's stopping you from using a-bunch-of-things
instead of hashing it?
I thought React won’t do a deep compare in that case?
it does not, that's correct
does a-bunch-of-things
change every render?
No, it doesn’t change often. But I’m now realizing that hashing is probably the same as using the thing directly
if the reference identity is stable, then I would just use the thing directly
e.g.
(def a-bunch-of-things [1 2 3 4])
the vector will only be created once, and React will always see the same object so it will only fire the effect oncewhere you run into issues is if you have something like this inside a render:
(let [a-bunch-of-things [1 2 3 4]]
(react/useEffect
#(do-thing)
#js [a-bunch-of-things]))
now the vector object gets reconstructed every render (even though it's the same value) and so React will see a new object and fire the effect every render