【问题标题】:Reagent: How to get new props from component-will-receive-props?Reagent:如何从 component-will-receive-props 中获取新的 props?
【发布时间】:2015-09-11 20:12:38
【问题描述】:

所以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获得旧道具,但这是旧道具,不是新收到的。

【问题讨论】:

    标签: clojurescript reagent


    【解决方案1】:

    好吧,我终于发现它是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

    【讨论】:

      【解决方案2】:

      我认为正确的方法是通过 props 函数。 An example here 显示了这一点。

      ;; assuming you have reagent required :as reagent
      
      (reagent/create-class
        {
        ...
      
        :should-component-update
        (fn [this]
          (println "next-props" (reagent/props this))
        ...
        })
      

      【讨论】:

      • 这将返回当前的道具,而不是新的道具,这是 OP 正在寻找的。​​span>
      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 2022-11-30
      • 2021-02-01
      • 2021-11-20
      • 2019-04-22
      • 2020-03-19
      • 2020-02-24
      • 2022-01-17
      相关资源
      最近更新 更多