2015-09-11 16 views
4

所以對於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得到舊道具,但它是舊的道具,沒有新收到。

回答

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)) 
    ... 
    }) 
+0

這將返回當前的道具,而不是新的道具,這是OP正在尋找的東西。 – wpcarro