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?
should not happen, do you have a code snippet?
Might take me a little while to synthesise something small enough. I'll try.
from the top of my head it could happen when rendering lists of items without providing :key
that’s not specific to any React wrappers though
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.
😄
@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
@dimonmartyn yes you can, but that’s usually not the best way to do it
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
(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)
Thanks. That’s exactly what I do. I don’t like it and will think about something better. 🙂 Thank you.