试剂:如何从“component-will-receive-props”中获取新的属性?

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

2个回答

4

1

我认为正确的方法是通过props函数来实现。这里有一个例子说明了这一点。

;; assuming you have reagent required :as reagent

(reagent/create-class
  {
  ...

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

这会返回当前的props而不是新的props,而这正是原帖作者所寻求的。 - wpcarro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接