Fork me on GitHub
#rum
<
2017-04-13
>
esp115:04:23

i ran into a situation where i’d like to have a component parameterize functionality in react lifecycle methods. basically i want a wrapper component for a bunch of different quil sketches, and i’d like to do something like (sketch-wrapper <sketch>), where the component will size itself, etc from the sketch parameters. the thing is i need to be able to call the particular sketch start function during :did-mount. normally in rum i’d use a mixin:

(defc sketch-wrapper < {:did-mount sketch-start-fn}
  [{:keys [sketch-start-fn]}]
  ...)
but that doesn’t work here because the component arguments aren’t available when defining the mixin this way. in reagent i could do something like:
(defn sketch-wrapper [{:keys [sketch-start-fn]}]
  (r/create-class
    {:component-did-mount sketch-start-fn
     ...
is there a way to do something like this in rum?

Niki17:04:46

@esp1

(defc sketch-wrapper < 
  { :did-mount 
    (fn [state]
      (let [args (:rum/args state)
            [arg] args
            {:keys [sketch-start-fn]} arg]
        (sketch-start-fn))) }
  [{:keys [sketch-start-fn]}]
  ...)

esp117:04:04

ah - great, thx!