fulcro

Mike Richards 2025-03-28T16:08:05.480689Z

Say I'm using hooks/use-memo (or something else that takes deps like hooks/use-effect), example here:

(defsc SomeComponent [this {:>/keys [name-info]}]
  {:use-hooks? true
   :ident :person/id
   :query [:person/id
           :person/age
           {:>/name-info [:person/first-name :person/last-name]}]}
  (let [greeting (hooks/use-memo #(expensive-greeting name-info) [name-info])]
    ...))
If this component re-renders because say, age changed but neither first-name nor last-name changed, will name-info have the same identity in the next render? Or is it built fresh from the app db each time? Obviously I could change this so that the deps vector was [first-name last-name] since they're both strings and wouldn't change identity:
(let [{:person/keys [first-name last-name]} name-info
      greeting (hooks/use-memo #(...) [first-name last-name])]
... but I'm wondering if it still works if I pass in the whole name-info map, or if I'd need to hack with hash for instance:
(hooks/use-memo #(...) [(hash name-info)])

Mike Richards 2025-03-31T13:40:31.541809Z

Got it, thank you! If a re-render was triggered from hooks/use-state would that also skip reconstructing props since the render would be coming from outside fulcro?

tony.kay 2025-03-31T21:28:48.439579Z

correct, if React re-renders the component, then it re-hands you the cached props it kept

1
tony.kay 2025-03-29T12:46:53.332229Z

each render, unless you use sync transactions (e.g. the !! variants) recreate the result from the db. so a join is reconstructed and the two won’t be identical (they will be equal, but I think react uses the faster identical check).