试剂:如何从组件接收道具中获取新道具?

时间:2015-09-11 20:12:39

标签: clojurescript reagent

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获取道具地图?我可以通过this(reagent/props this)获取旧道具,但它是旧道具,不是新收到的。

2 个答案:

答案 0 :(得分:4)

好的,我终于发现它是reagent.impl.util/extract-props。 所以(reagent.impl.util/extract-props new-argv)将返回新道具。

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

答案 1 :(得分:1)

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

;; assuming you have reagent required :as reagent

(reagent/create-class
  {
  ...

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