5

所以签名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?我可以从thisby获得旧道具(reagent/props this),但这是旧道具,不是新收到的。

4

2 回答 2

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

于 2015-09-11T20:30:30.187 回答
1

我认为正确的方法是通过 props 函数。这里的一个例子显示了这一点。

;; assuming you have reagent required :as reagent

(reagent/create-class
  {
  ...

  :should-component-update
  (fn [this]
    (println "next-props" (reagent/props this))
  ...
  })
于 2015-12-07T21:50:57.313 回答