2017-09-21 2 views
3

の内部で再レンダリングではないコンポーネントを、私は原子fooていない:試薬が被参照-INGの聞かせて

(defonce foo (r/atom "foo")) 

を私は親コンポーネントがあります。

(defn parent-component [] 
    (js/setTimeout #(reset! foo "bar") 5000) 
    (child-component {:foo foo})) 

をそして、私は子コンポーネントがあります。

(defn child-component [props] 
    (let [derefed (deref (:foo props))] 
    (fn [] 
     [:div 
     [:p derefed] 
     [:p (deref (:foo props))]]))) 

fooをリセットした後、2番目の段落のみが更新されます。

なぜこのように機能していますか?

答えて

4

フォーム2コンポーネントに関する再フレームのドキュメントから:https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components#form-2--a-function-returning-a-function

あなたは内部関数の中で再び外側の関数のパラメータを繰り返す必要があります:あなたは再フレームとそのを使用しているとき、このような場合のために、フォーム-2のコンポーネントを使用する必要はありません

(defn child-component [props] 
    (fn [props] 
    (let [derefed (deref (:foo props))] 
     [:div 
     [:p derefed] 
     [:p (deref (:foo props))]]))) 
+0

注意定期購読:https://github.com/Day8/re-frame/issues/218 –

関連する問題