Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reagent: How to get new props from component-will-receive-props?

So signature for component-will-receive-props is such:

https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L114

:component-will-receive-props (fn [this new-argv])

But new-args seems like it's function or js object. I was expecting it to be map of props. How do I get map of props from new-argv? I can get old props from this by (reagent/props this), but it's old props, not newly received.

like image 636
ma2s Avatar asked Sep 11 '15 20:09

ma2s


2 Answers

Ok I finally found out it's reagent.impl.util/extract-props. So (reagent.impl.util/extract-props new-argv) will return new props.

https://github.com/reagent-project/reagent/blob/v0.5.1-rc3/src/reagent/impl/util.cljs#L11

like image 115
ma2s Avatar answered Jan 01 '23 09:01

ma2s


I think the correct way to do this is through the props function. An example here shows this.

;; assuming you have reagent required :as reagent

(reagent/create-class
  {
  ...

  :should-component-update
  (fn [this]
    (println "next-props" (reagent/props this))
  ...
  })
like image 34
Jon Rose Avatar answered Jan 01 '23 08:01

Jon Rose