rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript | 0.12.8 https://github.com/tonsky/rum/blob/gh-pages/CHANGELOG.md#0128
pez 2018-09-21T08:24:49.000100Z

I'm having an issue with rum components doing a full remount on state change. We are porting stuff from reagent where this does not happen. Is this generally how it works with rum, or am I doing something wrong?

2018-09-21T08:27:33.000100Z

should not happen, do you have a code snippet?

pez 2018-09-21T08:30:20.000100Z

Might take me a little while to synthesise something small enough. I'll try.

2018-09-21T08:32:15.000100Z

from the top of my head it could happen when rendering lists of items without providing :key

2018-09-21T08:32:30.000100Z

that’s not specific to any React wrappers though

pez 2018-09-21T08:55:28.000100Z

Thanks for asking that question, @roman01la 😃 I found the problem when trying to shrink it down to a snippet. The problem was not in rum, nor in citrus, just in me.

2018-09-21T08:56:04.000200Z

😄

reptiloid 2018-09-21T10:41:16.000100Z

@roman01la Can I init local state using props (rum/local {:qty <qty from props>} ::local-state)? I just want to work with original qty from props and have a temporary one, so I can check if those qtys are different and then I can enable button and apply changes

2018-09-21T11:29:48.000100Z

@dimonmartyn yes you can, but that’s usually not the best way to do it

💯 1
2018-09-21T11:31:10.000100Z

you can update local state in any event handler inside of a component or do it in a custom mixin within one of lifecycle methods, depends on when you want to update the state

2018-09-21T11:36:08.000100Z

(defn derive-from-props [prop-getter state-key]
  {:did-mount (fn [st]
                     (reset! (get st state-key) (prop-getter (:rum/args st)))
                     st)})

(rum/defc App <
  (rum/local {} ::state)
  (derive-from-props first ::state)
  [_])

(App props)

reptiloid 2018-09-21T11:58:45.000100Z

Thanks. That’s exactly what I do. I don’t like it and will think about something better. 🙂 Thank you.