Fork me on GitHub
#rum
<
2018-09-21
>
pez08:09:49

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?

roman01la08:09:33

should not happen, do you have a code snippet?

pez08:09:20

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

roman01la08:09:15

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

roman01la08:09:30

that’s not specific to any React wrappers though

pez08:09:28

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.

reptiloid10:09:16

@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

roman01la11:09:48

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

💯 4
roman01la11:09:10

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

reptiloid11:09:45

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

roman01la11:09:08

(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)