clojurescript

roklenarcic 2025-10-01T09:49:48.965939Z

I am having a bit of an issue with UiX and ReFx, where I have a Router component and there’s a sibling in the tree that is a Dimmer div. This div is open/closed based on a value in ReFx db:

(reg-sub :inst-open? (fn [db _] (:inst-open? db)))
(reg-event-db :instructions (fn [db [_ v]] (assoc db :inst-open? v)))

(defn instructions-modal []
  (let [open? (use-sub [:inst-open?])]
    ($ Dimmer {:on open?
               :on-close (fn [] (dispatch [:instructions false]))} ....
The confusing part is that operating opening and closing this dimmer via dispatch also causes the Router which is a sibling in the tree to render. I don’t understand why. The router depends on this subscription:
(refx/reg-sub
  ::current
  (fn [db]
    (::current-route db)))

(defui Router [{:keys [children]}]
  (let [current-route (refx/use-sub [::current])]
    (println "ROUTE" current-route)
    (when current-route
      ($ (-> current-route :data :view)
         children))))
And the root render tree is:
(defui root []
  ($ :<>
     header
     ($ Router)
     (footer)
     (instructions-modal)))
Again, whenever I onen/close the instructions dimmer, that println in router gets printed, so that means that component gets rerendered. Why if none of the hooks in that tree changed?

p-himik 2025-10-01T09:51:32.610799Z

Why is it (instructions-modal) and not ($ instructions-modal)?

roklenarcic 2025-10-01T09:52:08.719629Z

Hm perhaps that’s the issue, the use-sub is not in a component of its own?

p-himik 2025-10-01T09:52:33.316589Z

I'd think so. No idea about ReFx but it seems to be similar to () vs. [] in Reagent's Hiccup.

roklenarcic 2025-10-01T09:52:47.405409Z

good eye, I didn’t even spot this problem

p-himik 2025-10-01T09:52:50.188359Z

And, of course, also (footer) instead of ($ footer).

roklenarcic 2025-10-01T09:53:11.858889Z

that one’s fine it doesn’t have any hooks

roklenarcic 2025-10-01T09:53:19.602719Z

it’s just a snippet of html

roklenarcic 2025-10-01T09:53:47.130489Z

that seems to have fixed it, thank you

roklenarcic 2025-10-01T09:54:10.165609Z

learning React, one mistake at a time

Roman Liutikov 2025-10-01T09:55:54.495599Z

I'd suggest to never call components as functions. A good rule of thumb is to always create React elements out of components, never call them as functions.

roklenarcic 2025-10-01T09:57:05.241709Z

Hey is there a way to force rerender of the whole tree?

Roman Liutikov 2025-10-01T09:57:16.374299Z

React component is not just producing markup, it encapsulates state/effects etc. using $ or <> in JSX you basically create an instance of the component

roklenarcic 2025-10-01T09:57:31.617699Z

on hot reloads the changes don’t show up sometimes

Roman Liutikov 2025-10-01T09:59:16.958569Z

> Hey is there a way to force rerender of the whole tree? I don't know. > on hot reloads the changes don’t show up sometimes is that related to uix/react or refx? what type of changes don't show up? do you have react-refresh setup https://github.com/pitch-io/uix/blob/master/docs/hot-reloading.md?

roklenarcic 2025-10-01T10:00:49.874139Z

I’ll try the react refresh (though that is solving the issue with state being reset).

Roman Liutikov 2025-10-01T10:03:39.764269Z

sounds like you don't have any hot reloading setup, that would explain why you don't see UI updates after reloads you either use traditional hot reloading (render from the root) or react-refresh, both are covered in the docs

roklenarcic 2025-10-01T10:10:57.086869Z

Nah it kinda works sometimes and sometimes not

roklenarcic 2025-10-01T10:11:11.249519Z

I’ll try with react-refresh

roklenarcic 2025-10-01T10:11:12.478309Z

thanks