Reagent:如何从 component-will-receive-props 获取新的 props?

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

所以 component-will-receive-props 的签名是这样的:

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

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

但是new-args好像是函数或者js对象。我期待它是道具地图。如何从 new-argv 获取道具地图?我可以通过(reagent/props this)this获得旧道具,但它是旧道具,不是新收到的。

好吧,我终于发现它是 reagent.impl.util/extract-props。 所以(reagent.impl.util/extract-props new-argv)会return新道具。

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

我认为正确的做法是通过道具功能。 An example here 显示了这一点。

;; assuming you have reagent required :as reagent

(reagent/create-class
  {
  ...

  :should-component-update
  (fn [this]
    (println "next-props" (reagent/props this))
  ...
  })